diff --git a/src/core/IronPython.Modules/ModuleOps.cs b/src/core/IronPython.Modules/ModuleOps.cs
index 9e3336a4d..2d7d678f2 100644
--- a/src/core/IronPython.Modules/ModuleOps.cs
+++ b/src/core/IronPython.Modules/ModuleOps.cs
@@ -376,7 +376,7 @@ public static uint GetUnsignedInt(object value, object type) {
public static long GetSignedLong(object value, object type) {
if (TryToIntStrict(value, out BigInteger bi)) {
- return unchecked((long)(ulong)(bi & uint.MaxValue));
+ return unchecked((long)(ulong)(bi & (TypecodeOps.IsCLong32Bit ? uint.MaxValue : ulong.MaxValue)));
}
if (PythonOps.TryGetBoundAttr(value, "_as_parameter_", out object asParam)) {
@@ -388,7 +388,7 @@ public static long GetSignedLong(object value, object type) {
public static ulong GetUnsignedLong(object value, object type) {
if (TryToIntStrict(value, out BigInteger bi)) {
- return (ulong)(bi & uint.MaxValue);
+ return (ulong)(bi & (TypecodeOps.IsCLong32Bit ? uint.MaxValue : ulong.MaxValue));
}
if (PythonOps.TryGetBoundAttr(value, "_as_parameter_", out object asParam)) {
diff --git a/src/core/IronPython.Modules/_ctypes/SimpleType.cs b/src/core/IronPython.Modules/_ctypes/SimpleType.cs
index 03504a09d..14475cc33 100644
--- a/src/core/IronPython.Modules/_ctypes/SimpleType.cs
+++ b/src/core/IronPython.Modules/_ctypes/SimpleType.cs
@@ -182,10 +182,11 @@ int INativeType.Size {
return 2;
case SimpleTypeKind.SignedInt:
case SimpleTypeKind.UnsignedInt:
- case SimpleTypeKind.SignedLong:
- case SimpleTypeKind.UnsignedLong:
case SimpleTypeKind.Single:
return 4;
+ case SimpleTypeKind.SignedLong:
+ case SimpleTypeKind.UnsignedLong:
+ return TypecodeOps.IsCLong32Bit ? 4 : 8;
case SimpleTypeKind.UnsignedLongLong:
case SimpleTypeKind.SignedLongLong:
case SimpleTypeKind.Double:
@@ -220,8 +221,8 @@ object INativeType.GetValue(MemoryHolder/*!*/ owner, object readingFrom, int off
case SimpleTypeKind.UnsignedShort: res = GetIntReturn((ushort)owner.ReadInt16(offset, _swap)); break;
case SimpleTypeKind.SignedInt: res = GetIntReturn(owner.ReadInt32(offset, _swap)); break;
case SimpleTypeKind.UnsignedInt: res = GetIntReturn((uint)owner.ReadInt32(offset, _swap)); break;
- case SimpleTypeKind.SignedLong: res = GetIntReturn(owner.ReadInt32(offset, _swap)); break;
- case SimpleTypeKind.UnsignedLong: res = GetIntReturn((uint)owner.ReadInt32(offset, _swap)); break;
+ case SimpleTypeKind.SignedLong: if (TypecodeOps.IsCLong32Bit) goto case SimpleTypeKind.SignedInt; else goto case SimpleTypeKind.SignedLongLong;
+ case SimpleTypeKind.UnsignedLong: if (TypecodeOps.IsCLong32Bit) goto case SimpleTypeKind.UnsignedInt; else goto case SimpleTypeKind.UnsignedLongLong;
case SimpleTypeKind.SignedLongLong: res = GetIntReturn(owner.ReadInt64(offset, _swap)); break;
case SimpleTypeKind.UnsignedLongLong: res = GetIntReturn((ulong)owner.ReadInt64(offset, _swap)); break;
case SimpleTypeKind.Single: res = GetSingleReturn(owner.ReadInt32(offset, _swap)); break;
@@ -259,8 +260,20 @@ object INativeType.SetValue(MemoryHolder/*!*/ owner, int offset, object value) {
case SimpleTypeKind.UnsignedShort: owner.WriteInt16(offset, unchecked((short)ModuleOps.GetUnsignedShort(value, this)), _swap); break;
case SimpleTypeKind.SignedInt: owner.WriteInt32(offset, ModuleOps.GetSignedInt(value, this), _swap); break;
case SimpleTypeKind.UnsignedInt: owner.WriteInt32(offset, unchecked((int)ModuleOps.GetUnsignedInt(value, this)), _swap); break;
- case SimpleTypeKind.SignedLong: owner.WriteInt32(offset, unchecked((int)ModuleOps.GetSignedLong(value, this)), _swap); break;
- case SimpleTypeKind.UnsignedLong: owner.WriteInt32(offset, unchecked((int)ModuleOps.GetUnsignedLong(value, this)), _swap); break;
+ case SimpleTypeKind.SignedLong:
+ if (TypecodeOps.IsCLong32Bit) {
+ owner.WriteInt32(offset, unchecked((int)ModuleOps.GetSignedLong(value, this)), _swap);
+ } else {
+ owner.WriteInt64(offset, ModuleOps.GetSignedLong(value, this), _swap);
+ }
+ break;
+ case SimpleTypeKind.UnsignedLong:
+ if (TypecodeOps.IsCLong32Bit) {
+ owner.WriteInt32(offset, unchecked((int)ModuleOps.GetUnsignedLong(value, this)), _swap);
+ } else {
+ owner.WriteInt64(offset, unchecked((long)ModuleOps.GetUnsignedLong(value, this)), _swap);
+ }
+ break;
case SimpleTypeKind.UnsignedLongLong: owner.WriteInt64(offset, unchecked((long)ModuleOps.GetUnsignedLongLong(value, this)), _swap); break;
case SimpleTypeKind.SignedLongLong: owner.WriteInt64(offset, ModuleOps.GetSignedLongLong(value, this), _swap); break;
case SimpleTypeKind.Single: owner.WriteInt32(offset, ModuleOps.GetSingleBits(value), _swap); break;
@@ -301,11 +314,13 @@ object INativeType.SetValue(MemoryHolder/*!*/ owner, int offset, object value) {
case SimpleTypeKind.UnsignedShort:
return typeof(ushort);
case SimpleTypeKind.SignedInt:
- case SimpleTypeKind.SignedLong:
return typeof(int);
case SimpleTypeKind.UnsignedInt:
- case SimpleTypeKind.UnsignedLong:
return typeof(uint);
+ case SimpleTypeKind.SignedLong:
+ return TypecodeOps.IsCLong32Bit ? typeof(int) : typeof(long);
+ case SimpleTypeKind.UnsignedLong:
+ return TypecodeOps.IsCLong32Bit ? typeof(uint) : typeof(ulong);
case SimpleTypeKind.SignedLongLong:
return typeof(long);
case SimpleTypeKind.UnsignedLongLong:
@@ -589,8 +604,9 @@ private Type GetPythonTypeWorker() {
case SimpleTypeKind.SignedShort:
case SimpleTypeKind.UnsignedShort:
case SimpleTypeKind.SignedInt:
- case SimpleTypeKind.SignedLong:
return typeof(int);
+ case SimpleTypeKind.SignedLong:
+ return TypecodeOps.IsCLong32Bit ? typeof(int) : typeof(object);
case SimpleTypeKind.UnsignedInt:
case SimpleTypeKind.UnsignedLong:
case SimpleTypeKind.UnsignedLongLong:
@@ -618,7 +634,6 @@ void INativeType.EmitReverseMarshalling(ILGenerator method, LocalOrArg value, Li
break;
case SimpleTypeKind.Boolean:
case SimpleTypeKind.SignedInt:
- case SimpleTypeKind.SignedLong:
break;
case SimpleTypeKind.Single:
method.Emit(OpCodes.Conv_R8);
@@ -630,6 +645,10 @@ void INativeType.EmitReverseMarshalling(ILGenerator method, LocalOrArg value, Li
case SimpleTypeKind.UnsignedLongLong:
EmitUIntToObject(method, value);
break;
+ case SimpleTypeKind.SignedLong:
+ if (TypecodeOps.IsCLong32Bit) break; // no conversion needed
+ EmitInt64ToObject(method, value);
+ break;
case SimpleTypeKind.SignedLongLong:
EmitInt64ToObject(method, value);
break;
diff --git a/src/core/IronPython.Modules/_ctypes/_ctypes.cs b/src/core/IronPython.Modules/_ctypes/_ctypes.cs
index 01de2d51a..acdd300c6 100644
--- a/src/core/IronPython.Modules/_ctypes/_ctypes.cs
+++ b/src/core/IronPython.Modules/_ctypes/_ctypes.cs
@@ -465,7 +465,7 @@ public static int set_last_error(int errorCode) {
}
public static int @sizeof(PythonType/*!*/ type) {
- if (!(type is INativeType simpleType)) {
+ if (type is not INativeType simpleType) {
throw PythonOps.TypeError("this type has no size");
}
diff --git a/src/core/IronPython.Modules/_struct.cs b/src/core/IronPython.Modules/_struct.cs
index 9758b8640..cdebb289c 100644
--- a/src/core/IronPython.Modules/_struct.cs
+++ b/src/core/IronPython.Modules/_struct.cs
@@ -142,12 +142,25 @@ public void __init__(CodeContext/*!*/ context, object fmt) {
break;
case FormatType.UnsignedInt:
for (int j = 0; j < curFormat.Count; j++) {
- WriteUInt(res, _isLittleEndian, GetULongValue(context, curObj++, values));
+ WriteUInt(res, _isLittleEndian, GetUIntValue(context, curObj++, values));
+ }
+ break;
+ case FormatType.Long:
+ for (int j = 0; j < curFormat.Count; j++) {
+ if (_isStandardized || TypecodeOps.IsCLong32Bit) {
+ WriteInt(res, _isLittleEndian, GetIntValue(context, curObj++, values));
+ } else {
+ WriteLong(res, _isLittleEndian, GetLongValue(context, curObj++, values));
+ }
}
break;
case FormatType.UnsignedLong:
for (int j = 0; j < curFormat.Count; j++) {
- WriteUInt(res, _isLittleEndian, GetULongValue(context, curObj++, values));
+ if (_isStandardized || TypecodeOps.IsCLong32Bit) {
+ WriteUInt(res, _isLittleEndian, GetUIntValue(context, curObj++, values));
+ } else {
+ WriteULong(res, _isLittleEndian, GetULongValue(context, curObj++, values));
+ }
}
break;
case FormatType.LongLong:
@@ -310,11 +323,28 @@ public void pack_into(CodeContext/*!*/ context, [NotNone] IBufferProtocol/*!*/ b
}
break;
case FormatType.UnsignedInt:
- case FormatType.UnsignedLong:
for (int j = 0; j < curFormat.Count; j++) {
res[res_idx++] = BigIntegerOps.__int__(CreateUIntValue(context, ref curIndex, _isLittleEndian, data));
}
break;
+ case FormatType.Long:
+ for (int j = 0; j < curFormat.Count; j++) {
+ if (_isStandardized || TypecodeOps.IsCLong32Bit) {
+ res[res_idx++] = CreateIntValue(context, ref curIndex, _isLittleEndian, data);
+ } else {
+ res[res_idx++] = BigIntegerOps.__int__(CreateLongValue(context, ref curIndex, _isLittleEndian, data));
+ }
+ }
+ break;
+ case FormatType.UnsignedLong:
+ for (int j = 0; j < curFormat.Count; j++) {
+ if (_isStandardized || TypecodeOps.IsCLong32Bit) {
+ res[res_idx++] = BigIntegerOps.__int__(CreateUIntValue(context, ref curIndex, _isLittleEndian, data));
+ } else {
+ res[res_idx++] = BigIntegerOps.__int__(CreateULongValue(context, ref curIndex, _isLittleEndian, data));
+ }
+ }
+ break;
case FormatType.LongLong:
for (int j = 0; j < curFormat.Count; j++) {
res[res_idx++] = BigIntegerOps.__int__(CreateLongValue(context, ref curIndex, _isLittleEndian, data));
@@ -472,7 +502,6 @@ private static Struct CompileAndCache(CodeContext/*!*/ context, string/*!*/ fmt)
count = 1;
break;
case 'i': // int
- case 'l': // long
res.Add(new Format(FormatType.Int, count));
count = 1;
break;
@@ -480,6 +509,10 @@ private static Struct CompileAndCache(CodeContext/*!*/ context, string/*!*/ fmt)
res.Add(new Format(FormatType.UnsignedInt, count));
count = 1;
break;
+ case 'l': // long
+ res.Add(new Format(FormatType.Long, count));
+ count = 1;
+ break;
case 'L': // unsigned long
res.Add(new Format(FormatType.UnsignedLong, count));
count = 1;
@@ -624,7 +657,7 @@ private void InitCountAndSize() {
encodingSize = Align(encodingSize, format.NativeSize);
}
- encodingSize += GetNativeSize(format.Type) * format.Count;
+ encodingSize += GetNativeSize(format.Type, _isStandardized) * format.Count;
}
_encodingCount = encodingCount;
_encodingSize = encodingSize;
@@ -729,6 +762,7 @@ private enum FormatType {
Int,
UnsignedInt,
+ Long,
UnsignedLong,
Float,
@@ -747,7 +781,7 @@ private enum FormatType {
SizeT,
}
- private static int GetNativeSize(FormatType c) {
+ private static int GetNativeSize(FormatType c, bool isStandardized) {
switch (c) {
case FormatType.Char:
case FormatType.SignedChar:
@@ -765,11 +799,13 @@ private static int GetNativeSize(FormatType c) {
return 2;
case FormatType.Int:
case FormatType.UnsignedInt:
- case FormatType.UnsignedLong:
case FormatType.Float:
case FormatType.SignedSizeT:
case FormatType.SizeT:
return 4;
+ case FormatType.Long:
+ case FormatType.UnsignedLong:
+ return isStandardized || TypecodeOps.IsCLong32Bit ? 4 : 8;
case FormatType.LongLong:
case FormatType.UnsignedLongLong:
case FormatType.Double:
@@ -786,16 +822,11 @@ private static int GetNativeSize(FormatType c) {
///
/// Struct used to store the format and the number of times it should be repeated.
///
- private readonly struct Format {
- public readonly FormatType Type;
- public readonly int Count;
-
- public Format(FormatType type, int count) {
- Type = type;
- Count = count;
- }
+ private readonly struct Format(FormatType type, int count) {
+ public readonly FormatType Type = type;
+ public readonly int Count = count;
- public int NativeSize => GetNativeSize(Type);
+ public int NativeSize => GetNativeSize(Type, isStandardized: false);
}
#endregion
@@ -1106,19 +1137,33 @@ internal static int GetIntValue(CodeContext/*!*/ context, int index, object[] ar
return res;
}
- internal static uint GetULongValue(CodeContext/*!*/ context, int index, object[] args) {
+ internal static uint GetUIntValue(CodeContext/*!*/ context, int index, object[] args) {
BigInteger val = GetIntegerValue(context, index, args);
if (!val.AsUInt32(out uint res))
throw Error(context, "argument out of range");
return res;
}
+ internal static long GetLongValue(CodeContext/*!*/ context, int index, object[] args) {
+ BigInteger val = GetIntegerValue(context, index, args);
+ if (!val.AsInt64(out long res))
+ throw Error(context, "argument out of range");
+ return res;
+ }
+
+ internal static ulong GetULongValue(CodeContext/*!*/ context, int index, object[] args) {
+ BigInteger val = GetIntegerValue(context, index, args);
+ if (!val.AsUInt64(out ulong res))
+ throw Error(context, "argument out of range");
+ return res;
+ }
+
internal static int GetSignedSizeT(CodeContext/*!*/ context, int index, object[] args) {
return GetIntValue(context, index, args);
}
internal static uint GetSizeT(CodeContext/*!*/ context, int index, object[] args) {
- return GetULongValue(context, index, args);
+ return GetUIntValue(context, index, args);
}
internal static ulong GetPointer(CodeContext/*!*/ context, int index, object[] args) {
diff --git a/src/core/IronPython.Modules/array.cs b/src/core/IronPython.Modules/array.cs
index 32a29b1f0..ed2919433 100644
--- a/src/core/IronPython.Modules/array.cs
+++ b/src/core/IronPython.Modules/array.cs
@@ -43,6 +43,10 @@ private static array ArrayReconstructor(CodeContext context, [NotNone] PythonTyp
throw PythonOps.ValueError("bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)");
var actualTypeCode = MachineFormatToTypeCode(mformat_code, out bool isBigEndian, out string? encoding);
+ if (TypeCodeToMachineFormat(typecode[0]) == mformat_code) {
+ // if typecodes are equivelent, use original
+ actualTypeCode = typecode;
+ }
var arrayType = DynamicHelpers.GetPythonTypeFromType(typeof(array));
@@ -106,6 +110,26 @@ static string MachineFormatToTypeCode(int machineFormat, out bool isBigEndian, o
}
}
+ private static int TypeCodeToMachineFormat(char typeCode) {
+ return typeCode switch
+ {
+ 'b' => 1,
+ 'B' => 0,
+ 'u' => 18,
+ 'h' => 4,
+ 'H' => 2,
+ 'i' => 8,
+ 'I' => 6,
+ 'l' => TypecodeOps.IsCLong32Bit ? 8 : 12,
+ 'L' => TypecodeOps.IsCLong32Bit ? 6 : 10,
+ 'q' => 12,
+ 'Q' => 10,
+ 'f' => 14,
+ 'd' => 16,
+ _ => throw new InvalidOperationException(),// should never happen
+ };
+ }
+
public static readonly BuiltinFunction _array_reconstructor = BuiltinFunction.MakeFunction(nameof(_array_reconstructor), ArrayUtils.ConvertAll(typeof(ArrayModule).GetMember(nameof(ArrayReconstructor), BindingFlags.NonPublic | BindingFlags.Static), x => (MethodBase)x), typeof(ArrayModule));
[PythonType]
@@ -166,8 +190,8 @@ private static ArrayData CreateData(char typecode) {
'H' => new ArrayData(),
'i' => new ArrayData(),
'I' => new ArrayData(),
- 'l' => new ArrayData(),
- 'L' => new ArrayData(),
+ 'l' => TypecodeOps.IsCLong32Bit ? new ArrayData() : new ArrayData(),
+ 'L' => TypecodeOps.IsCLong32Bit ? new ArrayData() : new ArrayData(),
'q' => new ArrayData(),
'Q' => new ArrayData(),
'f' => new ArrayData(),
@@ -420,8 +444,8 @@ public virtual object this[int index] {
case 'H': return (int)((ArrayData)_data)[index];
case 'i': return ((ArrayData)_data)[index];
case 'I': return (BigInteger)((ArrayData)_data)[index];
- case 'l': return ((ArrayData)_data)[index];
- case 'L': return (BigInteger)((ArrayData)_data)[index];
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': return (BigInteger)((ArrayData)_data)[index];
case 'Q': return (BigInteger)((ArrayData)_data)[index];
case 'f': return (double)((ArrayData)_data)[index];
@@ -447,8 +471,8 @@ internal byte[] RawGetItem(int index) {
case 'H': bw.Write(((ArrayData)_data)[index]); break;
case 'i': bw.Write(((ArrayData)_data)[index]); break;
case 'I': bw.Write(((ArrayData)_data)[index]); break;
- case 'l': bw.Write(((ArrayData)_data)[index]); break;
- case 'L': bw.Write(((ArrayData)_data)[index]); break;
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': bw.Write(((ArrayData)_data)[index]); break;
case 'Q': bw.Write(((ArrayData)_data)[index]); break;
case 'f': bw.Write(((ArrayData)_data)[index]); break;
@@ -552,26 +576,6 @@ public PythonTuple __reduce_ex__(CodeContext context, int version) {
tobytes()
),
dict);
-
- static int TypeCodeToMachineFormat(char typeCode) {
- return typeCode switch
- {
- 'b' => 1,
- 'B' => 0,
- 'u' => 18,
- 'h' => 4,
- 'H' => 2,
- 'i' => 8,
- 'I' => 6,
- 'l' => 8,
- 'L' => 6,
- 'q' => 12,
- 'Q' => 10,
- 'f' => 14,
- 'd' => 16,
- _ => throw new InvalidOperationException(),// should never happen
- };
- }
}
private void SliceAssign(int index, object? value) {
@@ -630,8 +634,8 @@ internal void ToStream(Stream ms) {
case 'H': bw.Write(((ArrayData)_data)[i]); break;
case 'i': bw.Write(((ArrayData)_data)[i]); break;
case 'I': bw.Write(((ArrayData)_data)[i]); break;
- case 'l': bw.Write(((ArrayData)_data)[i]); break;
- case 'L': bw.Write(((ArrayData)_data)[i]); break;
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': bw.Write(((ArrayData)_data)[i]); break;
case 'Q': bw.Write(((ArrayData)_data)[i]); break;
case 'f': bw.Write(((ArrayData)_data)[i]); break;
@@ -679,8 +683,8 @@ internal void FromStream(Stream ms) {
case 'H': ((ArrayData)_data).Add(br.ReadUInt16()); break;
case 'i': ((ArrayData)_data).Add(br.ReadInt32()); break;
case 'I': ((ArrayData)_data).Add(br.ReadUInt32()); break;
- case 'l': ((ArrayData)_data).Add(br.ReadInt32()); break;
- case 'L': ((ArrayData)_data).Add(br.ReadUInt32()); break;
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': ((ArrayData)_data).Add(br.ReadInt64()); break;
case 'Q': ((ArrayData)_data).Add(br.ReadUInt64()); break;
case 'f': ((ArrayData)_data).Add(br.ReadSingle()); break;
@@ -703,8 +707,8 @@ internal void FromStream(Stream ms, int index) {
case 'H': ((ArrayData)_data)[i] = br.ReadUInt16(); break;
case 'i': ((ArrayData)_data)[i] = br.ReadInt32(); break;
case 'I': ((ArrayData)_data)[i] = br.ReadUInt32(); break;
- case 'l': ((ArrayData)_data)[i] = br.ReadInt32(); break;
- case 'L': ((ArrayData)_data)[i] = br.ReadUInt32(); break;
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': ((ArrayData)_data)[i] = br.ReadInt64(); break;
case 'Q': ((ArrayData)_data)[i] = br.ReadUInt64(); break;
case 'f': ((ArrayData)_data)[i] = br.ReadSingle(); break;
@@ -733,8 +737,8 @@ internal long FromStream(Stream ms, int index, int nbytes) {
case 'H': ((ArrayData)_data)[i] = br.ReadUInt16(); break;
case 'i': ((ArrayData)_data)[i] = br.ReadInt32(); break;
case 'I': ((ArrayData)_data)[i] = br.ReadUInt32(); break;
- case 'l': ((ArrayData)_data)[i] = br.ReadInt32(); break;
- case 'L': ((ArrayData)_data)[i] = br.ReadUInt32(); break;
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': ((ArrayData)_data)[i] = br.ReadInt64(); break;
case 'Q': ((ArrayData)_data)[i] = br.ReadUInt64(); break;
case 'f': ((ArrayData)_data)[i] = br.ReadSingle(); break;
@@ -771,8 +775,8 @@ private byte[] ToBytes(int index) {
case 'H': return BitConverter.GetBytes(((ArrayData)_data)[index]);
case 'i': return BitConverter.GetBytes(((ArrayData)_data)[index]);
case 'I': return BitConverter.GetBytes(((ArrayData)_data)[index]);
- case 'l': return BitConverter.GetBytes(((ArrayData)_data)[index]);
- case 'L': return BitConverter.GetBytes(((ArrayData)_data)[index]);
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': return BitConverter.GetBytes(((ArrayData)_data)[index]);
case 'Q': return BitConverter.GetBytes(((ArrayData)_data)[index]);
case 'f': return BitConverter.GetBytes(((ArrayData)_data)[index]);
@@ -790,8 +794,8 @@ private object FromBytes(byte[] bytes) {
case 'H': return BitConverter.ToUInt16(bytes, 0);
case 'i': return BitConverter.ToInt32(bytes, 0);
case 'I': return BitConverter.ToUInt32(bytes, 0);
- case 'l': return BitConverter.ToInt32(bytes, 0);
- case 'L': return BitConverter.ToInt32(bytes, 0);
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': return BitConverter.ToInt64(bytes, 0);
case 'Q': return BitConverter.ToInt64(bytes, 0);
case 'f': return BitConverter.ToSingle(bytes, 0);
@@ -815,8 +819,8 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) {
case 'H': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
case 'i': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
case 'I': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
- case 'l': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
- case 'L': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
+ case 'l': if (TypecodeOps.IsCLong32Bit) goto case 'i'; else goto case 'q';
+ case 'L': if (TypecodeOps.IsCLong32Bit) goto case 'I'; else goto case 'Q';
case 'q': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
case 'Q': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
case 'f': dataTuple = PythonTuple.MakeTuple(((ArrayData)_data).Data); break;
diff --git a/src/core/IronPython/Runtime/MemoryView.cs b/src/core/IronPython/Runtime/MemoryView.cs
index 33912144f..a0d78ba49 100644
--- a/src/core/IronPython/Runtime/MemoryView.cs
+++ b/src/core/IronPython/Runtime/MemoryView.cs
@@ -589,7 +589,7 @@ private void SetItem(int offset, object? value) {
throw PythonOps.ValueError("memoryview: invalid value for format '{0}'", _format);
}
- if (typecode == 'Q') {
+ if (typecode is 'Q' or 'L' or 'N') {
value = Converter.ConvertToUInt64(value);
} else {
value = Converter.ConvertToInt64(value);
diff --git a/src/core/IronPython/Runtime/TypecodeOps.cs b/src/core/IronPython/Runtime/TypecodeOps.cs
index 58c5b6afe..cfd9ed3cf 100644
--- a/src/core/IronPython/Runtime/TypecodeOps.cs
+++ b/src/core/IronPython/Runtime/TypecodeOps.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
@@ -48,6 +48,9 @@ public static bool IsByteCode(char typecode)
public static bool IsFloatCode(char typecode)
=> typecode == 'f' || typecode == 'd';
+ public static bool IsCLong32Bit { get; }
+ = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || IntPtr.Size == 4;
+
public static int GetTypecodeWidth(char typecode) {
switch (typecode) {
case '?': // bool
@@ -61,12 +64,13 @@ public static int GetTypecodeWidth(char typecode) {
return 2;
case 'i': // signed int
case 'I': // unsigned int
- case 'l': // signed long
- case 'L': // unsigned long
case 'f': // float
case 'n': // signed index
case 'N': // unsigned index
return 4;
+ case 'l': // signed long
+ case 'L': // unsigned long
+ return IsCLong32Bit ? 4 : 8;
case 'q': // signed long long
case 'Q': // unsigned long long
case 'd': // double
@@ -102,16 +106,20 @@ public static bool TryGetFromBytes(char typecode, ReadOnlySpan bytes, [Not
case 'H':
result = MemoryMarshal.Read(bytes);
return true;
- case 'l':
case 'i':
case 'n':
result = MemoryMarshal.Read(bytes);
return true;
- case 'L':
case 'I':
case 'N':
result = MemoryMarshal.Read(bytes);
return true;
+ case 'l':
+ if (IsCLong32Bit) goto case 'i';
+ else goto case 'q';
+ case 'L':
+ if (IsCLong32Bit) goto case 'I';
+ else goto case 'Q';
case 'q':
result = MemoryMarshal.Read(bytes);
return true;
@@ -125,7 +133,7 @@ public static bool TryGetFromBytes(char typecode, ReadOnlySpan bytes, [Not
result = MemoryMarshal.Read(bytes);
return true;
case 'P':
- if (UIntPtr.Size == 4) goto case 'L';
+ if (UIntPtr.Size == 4) goto case 'I';
else goto case 'Q';
case 'r':
result = MemoryMarshal.Read(bytes);
@@ -160,16 +168,20 @@ public static bool TryGetBytes(char typecode, object obj, Span dest) {
case 'H':
var ushortVal = Convert.ToUInt16(obj);
return MemoryMarshal.TryWrite(dest, ref ushortVal);
- case 'l':
case 'i':
case 'n':
var intVal = Convert.ToInt32(obj);
return MemoryMarshal.TryWrite(dest, ref intVal);
- case 'L':
case 'I':
case 'N':
var uintVal = Convert.ToUInt32(obj);
return MemoryMarshal.TryWrite(dest, ref uintVal);
+ case 'l':
+ if (IsCLong32Bit) goto case 'i';
+ else goto case 'q';
+ case 'L':
+ if (IsCLong32Bit) goto case 'I';
+ else goto case 'Q';
case 'q':
var longVal = Convert.ToInt64(obj);
return MemoryMarshal.TryWrite(dest, ref longVal);
@@ -239,17 +251,21 @@ public static bool CausesOverflow(object value, char typecode) {
maxValue = ushort.MaxValue;
break;
case 'i': // signed int
- case 'l': // signed long
case 'n': // signed index
minValue = int.MinValue;
maxValue = int.MaxValue;
break;
case 'I': // unsigned int
- case 'L': // unsigned long
case 'N': // unsigned index
minValue = uint.MinValue;
maxValue = uint.MaxValue;
break;
+ case 'l': // signed long
+ if (IsCLong32Bit) goto case 'i';
+ else goto case 'q';
+ case 'L': // unsigned long
+ if (IsCLong32Bit) goto case 'I';
+ goto case 'Q';
case 'q': // signed long long
minValue = long.MinValue;
maxValue = long.MaxValue;
diff --git a/tests/ctypes_test/Makefile b/tests/ctypes_test/Makefile
index 535788a05..5724155c3 100644
--- a/tests/ctypes_test/Makefile
+++ b/tests/ctypes_test/Makefile
@@ -2,7 +2,7 @@ OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
MACHINE ?= $(shell uname -m)
BITS ?= 64
CC = gcc
-CFLAGS = -fPIC -Wall -Wextra -O2 -g
+CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -O2 -g
LDFLAGS = -shared
RM = rm -f
PLATFORM = $(OS)_$(MACHINE)
diff --git a/tests/ctypes_test/_ctypes_test.c b/tests/ctypes_test/_ctypes_test.c
index 4ab50391e..b68b0d2b9 100644
--- a/tests/ctypes_test/_ctypes_test.c
+++ b/tests/ctypes_test/_ctypes_test.c
@@ -1,3 +1,14 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define HAVE_LONG_LONG
+#define PY_LONG_LONG long long
+
#ifdef MS_WIN32
#include
#endif
@@ -8,87 +19,47 @@
#define EXPORT(x) x
#endif
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
/* some functions handy for testing */
-EXPORT(int32_t)
- _testfunc_cbk_reg_int(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e,
- int32_t(*func)(int32_t, int32_t, int32_t, int32_t, int32_t))
+EXPORT(int)
+_testfunc_cbk_reg_int(int a, int b, int c, int d, int e,
+ int (*func)(int, int, int, int, int))
{
return func(a*a, b*b, c*c, d*d, e*e);
}
EXPORT(double)
- _testfunc_cbk_reg_double(double a, double b, double c, double d, double e,
- double(*func)(double, double, double, double, double))
+_testfunc_cbk_reg_double(double a, double b, double c, double d, double e,
+ double (*func)(double, double, double, double, double))
{
return func(a*a, b*b, c*c, d*d, e*e);
}
/*
-* This structure should be the same as in test_callbacks.py and the
-* method test_callback_large_struct. See issues 17310 and 20160: the
-* structure must be larger than 8 bytes int32_t.
-*/
+ * This structure should be the same as in test_callbacks.py and the
+ * method test_callback_large_struct. See issues 17310 and 20160: the
+ * structure must be larger than 8 bytes long.
+ */
typedef struct {
- uint32_t first;
- uint32_t second;
- uint32_t third;
+ unsigned long first;
+ unsigned long second;
+ unsigned long third;
} Test;
EXPORT(void)
- _testfunc_cbk_large_struct(Test in, void(*func)(Test))
+_testfunc_cbk_large_struct(Test in, void (*func)(Test))
{
func(in);
}
-/*
-* See issue 29565. Update a structure passed by value;
-* the caller should not see any change.
-*/
-
-EXPORT(void)
- _testfunc_large_struct_update_value(Test in)
-{
- ((volatile Test *)&in)->first = 0x0badf00d;
- ((volatile Test *)&in)->second = 0x0badf00d;
- ((volatile Test *)&in)->third = 0x0badf00d;
-}
-
-typedef struct {
- uint32_t first;
- uint32_t second;
-} TestReg;
-
-
-EXPORT(TestReg) last_tfrsuv_arg = { 0 };
-
-
-EXPORT(void)
- _testfunc_reg_struct_update_value(TestReg in)
-{
- last_tfrsuv_arg = in;
- ((volatile TestReg *)&in)->first = 0x0badf00d;
- ((volatile TestReg *)&in)->second = 0x0badf00d;
-}
-
-
-EXPORT(void)testfunc_array(int32_t values[4])
+EXPORT(void)testfunc_array(int values[4])
{
printf("testfunc_array %d %d %d %d\n",
- values[0],
- values[1],
- values[2],
- values[3]);
+ values[0],
+ values[1],
+ values[2],
+ values[3]);
}
EXPORT(long double)testfunc_Ddd(double a, double b)
@@ -107,16 +78,16 @@ EXPORT(long double)testfunc_DDD(long double a, long double b)
return result;
}
-EXPORT(int32_t)testfunc_iii(int32_t a, int32_t b)
+EXPORT(int)testfunc_iii(int a, int b)
{
- int32_t result = a * b;
+ int result = a * b;
printf("testfunc_iii(%p, %p)\n", &a, &b);
return result;
}
-EXPORT(int32_t)myprintf(char *fmt, ...)
+EXPORT(int)myprintf(char *fmt, ...)
{
- int32_t result;
+ int result;
va_list argptr;
va_start(argptr, fmt);
result = vprintf(fmt, argptr);
@@ -129,7 +100,7 @@ EXPORT(char *)my_strtok(char *token, const char *delim)
return strtok(token, delim);
}
-EXPORT(char *)my_strchr(const char *s, int32_t c)
+EXPORT(char *)my_strchr(const char *s, int c)
{
return strchr(s, c);
}
@@ -140,50 +111,50 @@ EXPORT(double) my_sqrt(double a)
return sqrt(a);
}
-EXPORT(void) my_qsort(void *base, size_t num, size_t width, int32_t(*compare)(const void*, const void*))
+EXPORT(void) my_qsort(void *base, size_t num, size_t width, int(*compare)(const void*, const void*))
{
qsort(base, num, width, compare);
}
-EXPORT(int32_t *) _testfunc_ai8(int32_t a[8])
+EXPORT(int *) _testfunc_ai8(int a[8])
{
return a;
}
-EXPORT(void) _testfunc_v(int32_t a, int32_t b, int32_t *presult)
+EXPORT(void) _testfunc_v(int a, int b, int *presult)
{
*presult = a + b;
}
-EXPORT(int32_t) _testfunc_i_bhilfd(int8_t b, short h, int32_t i, int32_t l, float f, double d)
+EXPORT(int) _testfunc_i_bhilfd(signed char b, short h, int i, long l, float f, double d)
{
- /* printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n",
- b, h, i, l, f, d);
- */
- return (int32_t)(b + h + i + l + f + d);
+/* printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n",
+ b, h, i, l, f, d);
+*/
+ return (int)(b + h + i + l + f + d);
}
-EXPORT(float) _testfunc_f_bhilfd(int8_t b, short h, int32_t i, int32_t l, float f, double d)
+EXPORT(float) _testfunc_f_bhilfd(signed char b, short h, int i, long l, float f, double d)
{
- /* printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n",
- b, h, i, l, f, d);
- */
+/* printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n",
+ b, h, i, l, f, d);
+*/
return (float)(b + h + i + l + f + d);
}
-EXPORT(double) _testfunc_d_bhilfd(int8_t b, short h, int32_t i, int32_t l, float f, double d)
+EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f, double d)
{
- /* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
- b, h, i, l, f, d);
- */
+/* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
+ b, h, i, l, f, d);
+*/
return (double)(b + h + i + l + f + d);
}
-EXPORT(long double) _testfunc_D_bhilfD(int8_t b, short h, int32_t i, int32_t l, float f, long double d)
+EXPORT(long double) _testfunc_D_bhilfD(signed char b, short h, int i, long l, float f, long double d)
{
- /* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
- b, h, i, l, f, d);
- */
+/* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
+ b, h, i, l, f, d);
+*/
return (long double)(b + h + i + l + f + d);
}
@@ -192,9 +163,9 @@ EXPORT(char *) _testfunc_p_p(void *s)
return (char *)s;
}
-EXPORT(void *) _testfunc_c_p_p(int32_t *argcp, char **argv)
+EXPORT(void *) _testfunc_c_p_p(int *argcp, char **argv)
{
- return argv[(*argcp) - 1];
+ return argv[(*argcp)-1];
}
EXPORT(void *) get_strchr(void)
@@ -204,7 +175,7 @@ EXPORT(void *) get_strchr(void)
EXPORT(char *) my_strdup(char *src)
{
- char *dst = (char *)malloc(strlen(src) + 1);
+ char *dst = (char *)malloc(strlen(src)+1);
if (!dst)
return NULL;
strcpy(dst, src);
@@ -216,13 +187,14 @@ EXPORT(void)my_free(void *ptr)
free(ptr);
}
+#ifdef HAVE_WCHAR_H
EXPORT(wchar_t *) my_wcsdup(wchar_t *src)
{
size_t len = wcslen(src);
wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
if (ptr == NULL)
return NULL;
- memcpy(ptr, src, (len + 1) * sizeof(wchar_t));
+ memcpy(ptr, src, (len+1) * sizeof(wchar_t));
return ptr;
}
@@ -230,6 +202,7 @@ EXPORT(size_t) my_wcslen(wchar_t *src)
{
return wcslen(src);
}
+#endif
#ifndef MS_WIN32
# ifndef __stdcall
@@ -238,51 +211,52 @@ EXPORT(size_t) my_wcslen(wchar_t *src)
#endif
typedef struct {
- int32_t(*c)(int32_t, int32_t);
- int32_t(__stdcall *s)(int32_t, int32_t);
+ int (*c)(int, int);
+ int (__stdcall *s)(int, int);
} FUNCS;
-EXPORT(int32_t) _testfunc_callfuncp(FUNCS *fp)
+EXPORT(int) _testfunc_callfuncp(FUNCS *fp)
{
fp->c(1, 2);
fp->s(3, 4);
return 0;
}
-EXPORT(int32_t) _testfunc_deref_pointer(int32_t *pi)
+EXPORT(int) _testfunc_deref_pointer(int *pi)
{
return *pi;
}
#ifdef MS_WIN32
-EXPORT(int32_t) _testfunc_piunk(IUnknown FAR *piunk)
+EXPORT(int) _testfunc_piunk(IUnknown FAR *piunk)
{
piunk->lpVtbl->AddRef(piunk);
return piunk->lpVtbl->Release(piunk);
}
#endif
-EXPORT(int32_t) _testfunc_callback_with_pointer(int32_t(*func)(int32_t *))
+EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *))
{
- int32_t table[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ int table[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
return (*func)(table);
}
-EXPORT(int64_t) _testfunc_q_bhilfdq(int8_t b, short h, int32_t i, int32_t l, float f,
- double d, int64_t q)
+#ifdef HAVE_LONG_LONG
+EXPORT(PY_LONG_LONG) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
+ double d, PY_LONG_LONG q)
{
- return (int64_t)(b + h + i + l + f + d + q);
+ return (PY_LONG_LONG)(b + h + i + l + f + d + q);
}
-EXPORT(int64_t) _testfunc_q_bhilfd(int8_t b, short h, int32_t i, int32_t l, float f, double d)
+EXPORT(PY_LONG_LONG) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d)
{
- return (int64_t)(b + h + i + l + f + d);
+ return (PY_LONG_LONG)(b + h + i + l + f + d);
}
-EXPORT(int32_t) _testfunc_callback_i_if(int32_t value, int32_t(*func)(int32_t))
+EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int))
{
- int32_t sum = 0;
+ int sum = 0;
while (value != 0) {
sum += func(value);
value /= 2;
@@ -290,10 +264,10 @@ EXPORT(int32_t) _testfunc_callback_i_if(int32_t value, int32_t(*func)(int32_t))
return sum;
}
-EXPORT(int64_t) _testfunc_callback_q_qf(int64_t value,
- int64_t(*func)(int64_t))
+EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value,
+ PY_LONG_LONG (*func)(PY_LONG_LONG))
{
- int64_t sum = 0;
+ PY_LONG_LONG sum = 0;
while (value != 0) {
sum += func(value);
@@ -302,6 +276,8 @@ EXPORT(int64_t) _testfunc_callback_q_qf(int64_t value,
return sum;
}
+#endif
+
typedef struct {
char *name;
char *value;
@@ -309,31 +285,31 @@ typedef struct {
typedef struct {
char *name;
- int32_t num_spams;
+ int num_spams;
SPAM *spams;
} EGG;
SPAM my_spams[2] = {
{ "name1", "value1" },
-{ "name2", "value2" },
+ { "name2", "value2" },
};
EGG my_eggs[1] = {
{ "first egg", 1, my_spams }
};
-EXPORT(int32_t) getSPAMANDEGGS(EGG **eggs)
+EXPORT(int) getSPAMANDEGGS(EGG **eggs)
{
*eggs = my_eggs;
return 1;
}
typedef struct tagpoint {
- int32_t x;
- int32_t y;
+ int x;
+ int y;
} point;
-EXPORT(int32_t) _testfunc_byval(point in, point *pout)
+EXPORT(int) _testfunc_byval(point in, point *pout)
{
if (pout) {
pout->x = in.x;
@@ -342,27 +318,27 @@ EXPORT(int32_t) _testfunc_byval(point in, point *pout)
return in.x + in.y;
}
-EXPORT(int32_t) an_integer = 42;
+EXPORT (int) an_integer = 42;
-EXPORT(int32_t) get_an_integer(void)
+EXPORT(int) get_an_integer(void)
{
return an_integer;
}
EXPORT(double)
- integrate(double a, double b, double(*f)(double), int32_t nstep)
+integrate(double a, double b, double (*f)(double), long nstep)
{
- double x, sum = 0.0, dx = (b - a) / (double)nstep;
- for (x = a + 0.5*dx; (b - x)*(x - a) > 0.0; x += dx)
+ double x, sum=0.0, dx=(b-a)/(double)nstep;
+ for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx)
sum += f(x);
- return sum / (double)nstep;
+ return sum/(double)nstep;
}
typedef struct {
- void(*initialize)(void *(*)(int32_t), void(*)(void *));
+ void (*initialize)(void *(*)(int), void(*)(void *));
} xxx_library;
-static void _xxx_init(void *(*Xalloc)(int32_t), void(*Xfree)(void *))
+static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *))
{
void *ptr;
@@ -390,26 +366,26 @@ EXPORT(void) GetString(BSTR *pbstr)
}
#endif
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-EXPORT(void) _py_func_si(char *s, int32_t i)
+/*
+ * Some do-nothing functions, for speed tests
+ */
+EXPORT(void) _py_func_si(char *s, int i)
{
}
-#pragma GCC diagnostic pop
EXPORT(void) _py_func(void)
{
}
-EXPORT(int64_t) last_tf_arg_s = 0;
-EXPORT(uint64_t) last_tf_arg_u = 0;
+EXPORT(PY_LONG_LONG) last_tf_arg_s;
+EXPORT(unsigned PY_LONG_LONG) last_tf_arg_u;
struct BITS {
- int32_t A : 1, B : 2, C : 3, D : 4, E : 5, F : 6, G : 7, H : 8, I : 9;
- short M : 1, N : 2, O : 3, P : 4, Q : 5, R : 6, S : 7;
+ int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
+ short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7;
};
-EXPORT(void) set_bitfields(struct BITS *bits, char name, int32_t value)
+EXPORT(void) set_bitfields(struct BITS *bits, char name, int value)
{
switch (name) {
case 'A': bits->A = value; break;
@@ -432,7 +408,7 @@ EXPORT(void) set_bitfields(struct BITS *bits, char name, int32_t value)
}
}
-EXPORT(int32_t) unpack_bitfields(struct BITS *bits, char name)
+EXPORT(int) unpack_bitfields(struct BITS *bits, char name)
{
switch (name) {
case 'A': return bits->A;
@@ -456,73 +432,70 @@ EXPORT(int32_t) unpack_bitfields(struct BITS *bits, char name)
return 0;
}
-#define S last_tf_arg_s = (int64_t)c
-#define U last_tf_arg_u = (uint64_t)c
+#define S last_tf_arg_s = (PY_LONG_LONG)c
+#define U last_tf_arg_u = (unsigned PY_LONG_LONG)c
-EXPORT(int8_t) tf_b(int8_t c) { S; return c / 3; }
-EXPORT(uint8_t) tf_B(uint8_t c) { U; return c / 3; }
-EXPORT(short) tf_h(short c) { S; return c / 3; }
-EXPORT(uint16_t) tf_H(uint16_t c) { U; return c / 3; }
-EXPORT(int32_t) tf_i(int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) tf_I(uint32_t c) { U; return c / 3; }
-EXPORT(int32_t) tf_l(int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) tf_L(uint32_t c) { U; return c / 3; }
-EXPORT(int64_t) tf_q(int64_t c) { S; return c / 3; }
-EXPORT(uint64_t) tf_Q(uint64_t c) { U; return c / 3; }
-EXPORT(float) tf_f(float c) { S; return c / 3; }
-EXPORT(double) tf_d(double c) { S; return c / 3; }
-EXPORT(long double) tf_D(long double c) { S; return c / 3; }
+EXPORT(signed char) tf_b(signed char c) { S; return c/3; }
+EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; }
+EXPORT(short) tf_h(short c) { S; return c/3; }
+EXPORT(unsigned short) tf_H(unsigned short c) { U; return c/3; }
+EXPORT(int) tf_i(int c) { S; return c/3; }
+EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; }
+EXPORT(long) tf_l(long c) { S; return c/3; }
+EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; }
+EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { S; return c/3; }
+EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
+EXPORT(float) tf_f(float c) { S; return c/3; }
+EXPORT(double) tf_d(double c) { S; return c/3; }
+EXPORT(long double) tf_D(long double c) { S; return c/3; }
#ifdef MS_WIN32
-EXPORT(int8_t) __stdcall s_tf_b(int8_t c) { S; return c / 3; }
-EXPORT(uint8_t) __stdcall s_tf_B(uint8_t c) { U; return c / 3; }
-EXPORT(short) __stdcall s_tf_h(short c) { S; return c / 3; }
-EXPORT(uint16_t) __stdcall s_tf_H(uint16_t c) { U; return c / 3; }
-EXPORT(int32_t) __stdcall s_tf_i(int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) __stdcall s_tf_I(uint32_t c) { U; return c / 3; }
-EXPORT(int32_t) __stdcall s_tf_l(int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) __stdcall s_tf_L(uint32_t c) { U; return c / 3; }
-EXPORT(int64_t) __stdcall s_tf_q(int64_t c) { S; return c / 3; }
-EXPORT(uint64_t) __stdcall s_tf_Q(uint64_t c) { U; return c / 3; }
-EXPORT(float) __stdcall s_tf_f(float c) { S; return c / 3; }
-EXPORT(double) __stdcall s_tf_d(double c) { S; return c / 3; }
-EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c / 3; }
+EXPORT(signed char) __stdcall s_tf_b(signed char c) { S; return c/3; }
+EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { U; return c/3; }
+EXPORT(short) __stdcall s_tf_h(short c) { S; return c/3; }
+EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { U; return c/3; }
+EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; }
+EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; }
+EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; }
+EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; }
+EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { S; return c/3; }
+EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
+EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; }
+EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; }
+EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; }
#endif
/*******/
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-EXPORT(int8_t) tf_bb(int8_t x, int8_t c) { S; return c / 3; }
-EXPORT(uint8_t) tf_bB(int8_t x, uint8_t c) { U; return c / 3; }
-EXPORT(short) tf_bh(int8_t x, short c) { S; return c / 3; }
-EXPORT(uint16_t) tf_bH(int8_t x, uint16_t c) { U; return c / 3; }
-EXPORT(int32_t) tf_bi(int8_t x, int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) tf_bI(int8_t x, uint32_t c) { U; return c / 3; }
-EXPORT(int32_t) tf_bl(int8_t x, int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) tf_bL(int8_t x, uint32_t c) { U; return c / 3; }
-EXPORT(int64_t) tf_bq(int8_t x, int64_t c) { S; return c / 3; }
-EXPORT(uint64_t) tf_bQ(int8_t x, uint64_t c) { U; return c / 3; }
-EXPORT(float) tf_bf(int8_t x, float c) { S; return c / 3; }
-EXPORT(double) tf_bd(int8_t x, double c) { S; return c / 3; }
-EXPORT(long double) tf_bD(int8_t x, long double c) { S; return c / 3; }
-EXPORT(void) tv_i(int32_t c) { S; return; }
-#pragma GCC diagnostic pop
+EXPORT(signed char) tf_bb(signed char x, signed char c) { S; return c/3; }
+EXPORT(unsigned char) tf_bB(signed char x, unsigned char c) { U; return c/3; }
+EXPORT(short) tf_bh(signed char x, short c) { S; return c/3; }
+EXPORT(unsigned short) tf_bH(signed char x, unsigned short c) { U; return c/3; }
+EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; }
+EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; }
+EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; }
+EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; }
+EXPORT(PY_LONG_LONG) tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
+EXPORT(unsigned PY_LONG_LONG) tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
+EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; }
+EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; }
+EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; }
+EXPORT(void) tv_i(int c) { S; return; }
#ifdef MS_WIN32
-EXPORT(int8_t) __stdcall s_tf_bb(int8_t x, int8_t c) { S; return c / 3; }
-EXPORT(uint8_t) __stdcall s_tf_bB(int8_t x, uint8_t c) { U; return c / 3; }
-EXPORT(short) __stdcall s_tf_bh(int8_t x, short c) { S; return c / 3; }
-EXPORT(uint16_t) __stdcall s_tf_bH(int8_t x, uint16_t c) { U; return c / 3; }
-EXPORT(int32_t) __stdcall s_tf_bi(int8_t x, int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) __stdcall s_tf_bI(int8_t x, uint32_t c) { U; return c / 3; }
-EXPORT(int32_t) __stdcall s_tf_bl(int8_t x, int32_t c) { S; return c / 3; }
-EXPORT(uint32_t) __stdcall s_tf_bL(int8_t x, uint32_t c) { U; return c / 3; }
-EXPORT(int64_t) __stdcall s_tf_bq(int8_t x, int64_t c) { S; return c / 3; }
-EXPORT(uint64_t) __stdcall s_tf_bQ(int8_t x, uint64_t c) { U; return c / 3; }
-EXPORT(float) __stdcall s_tf_bf(int8_t x, float c) { S; return c / 3; }
-EXPORT(double) __stdcall s_tf_bd(int8_t x, double c) { S; return c / 3; }
-EXPORT(long double) __stdcall s_tf_bD(int8_t x, long double c) { S; return c / 3; }
-EXPORT(void) __stdcall s_tv_i(int32_t c) { S; return; }
+EXPORT(signed char) __stdcall s_tf_bb(signed char x, signed char c) { S; return c/3; }
+EXPORT(unsigned char) __stdcall s_tf_bB(signed char x, unsigned char c) { U; return c/3; }
+EXPORT(short) __stdcall s_tf_bh(signed char x, short c) { S; return c/3; }
+EXPORT(unsigned short) __stdcall s_tf_bH(signed char x, unsigned short c) { U; return c/3; }
+EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; }
+EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; }
+EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; }
+EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; }
+EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
+EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
+EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; }
+EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; }
+EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; }
+EXPORT(void) __stdcall s_tv_i(int c) { S; return; }
#endif
/********/
@@ -530,20 +503,20 @@ EXPORT(void) __stdcall s_tv_i(int32_t c) { S; return; }
#ifndef MS_WIN32
typedef struct {
- int32_t x;
- int32_t y;
+ long x;
+ long y;
} POINT;
typedef struct {
- int32_t left;
- int32_t top;
- int32_t right;
- int32_t bottom;
+ long left;
+ long top;
+ long right;
+ long bottom;
} RECT;
#endif
-EXPORT(int32_t) PointInRect(RECT *prc, POINT pt)
+EXPORT(int) PointInRect(RECT *prc, POINT pt)
{
if (pt.x < prc->left)
return 0;
@@ -556,13 +529,13 @@ EXPORT(int32_t) PointInRect(RECT *prc, POINT pt)
return 1;
}
-EXPORT(int32_t left = 10);
-EXPORT(int32_t top = 20);
-EXPORT(int32_t right = 30);
-EXPORT(int32_t bottom = 40);
+EXPORT(long left = 10);
+EXPORT(long top = 20);
+EXPORT(long right = 30);
+EXPORT(long bottom = 40);
-EXPORT(RECT) ReturnRect(int32_t i, RECT ar, RECT* br, POINT cp, RECT dr,
- RECT *er, POINT fp, RECT gr)
+EXPORT(RECT) ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr,
+ RECT *er, POINT fp, RECT gr)
{
/*Check input */
if (ar.left + br->left + dr.left + er->left + gr.left != left * 5)
@@ -583,7 +556,7 @@ EXPORT(RECT) ReturnRect(int32_t i, RECT ar, RECT* br, POINT cp, RECT dr,
{
ar.left = -200;
}
- switch (i)
+ switch(i)
{
case 0:
return ar;
@@ -612,7 +585,7 @@ EXPORT(S2H) ret_2h_func(S2H inp)
}
typedef struct {
- int32_t a, b, c, d, e, f, g, h;
+ int a, b, c, d, e, f, g, h;
} S8I;
EXPORT(S8I) ret_8i_func(S8I inp)
@@ -628,18 +601,18 @@ EXPORT(S8I) ret_8i_func(S8I inp)
return inp;
}
-EXPORT(int32_t) GetRectangle(int32_t flag, RECT *prect)
+EXPORT(int) GetRectangle(int flag, RECT *prect)
{
if (flag == 0)
return 0;
- prect->left = (int32_t)flag;
- prect->top = (int32_t)flag + 1;
- prect->right = (int32_t)flag + 2;
- prect->bottom = (int32_t)flag + 3;
+ prect->left = (int)flag;
+ prect->top = (int)flag + 1;
+ prect->right = (int)flag + 2;
+ prect->bottom = (int)flag + 3;
return 1;
}
-EXPORT(void) TwoOutArgs(int32_t a, int32_t *pi, int32_t b, int32_t *pj)
+EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj)
{
*pi += a;
*pj += b;
@@ -655,7 +628,7 @@ EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); }
#include
#include
-EXPORT(HRESULT) KeepObject(IUnknown *punk)
+EXPORT (HRESULT) KeepObject(IUnknown *punk)
{
static IUnknown *pobj;
if (punk)
diff --git a/tests/suite/_ctypes_test_darwin_arm64.pyd b/tests/suite/_ctypes_test_darwin_arm64.pyd
index f9be35a8b..ae5b989b5 100755
Binary files a/tests/suite/_ctypes_test_darwin_arm64.pyd and b/tests/suite/_ctypes_test_darwin_arm64.pyd differ
diff --git a/tests/suite/_ctypes_test_darwin_x86_64.pyd b/tests/suite/_ctypes_test_darwin_x86_64.pyd
index ade41f826..f924090ab 100755
Binary files a/tests/suite/_ctypes_test_darwin_x86_64.pyd and b/tests/suite/_ctypes_test_darwin_x86_64.pyd differ
diff --git a/tests/suite/_ctypes_test_linux_aarch64.pyd b/tests/suite/_ctypes_test_linux_aarch64.pyd
index 60134028b..4899a64f6 100755
Binary files a/tests/suite/_ctypes_test_linux_aarch64.pyd and b/tests/suite/_ctypes_test_linux_aarch64.pyd differ
diff --git a/tests/suite/_ctypes_test_linux_i686.pyd b/tests/suite/_ctypes_test_linux_i686.pyd
old mode 100644
new mode 100755
index 4c7b25dee..3e8f5a186
Binary files a/tests/suite/_ctypes_test_linux_i686.pyd and b/tests/suite/_ctypes_test_linux_i686.pyd differ
diff --git a/tests/suite/_ctypes_test_linux_x86_64.pyd b/tests/suite/_ctypes_test_linux_x86_64.pyd
old mode 100644
new mode 100755
index cf2ebf7df..b7fe4fb93
Binary files a/tests/suite/_ctypes_test_linux_x86_64.pyd and b/tests/suite/_ctypes_test_linux_x86_64.pyd differ
diff --git a/tests/suite/modules/io_related/test__bytesio.py b/tests/suite/modules/io_related/test__bytesio.py
index db8f9621e..3f3fe5c3b 100644
--- a/tests/suite/modules/io_related/test__bytesio.py
+++ b/tests/suite/modules/io_related/test__bytesio.py
@@ -11,7 +11,9 @@
from _io import BytesIO
-from iptest import big, run_test
+from iptest import big, is_32, is_windows, run_test
+
+is_long32bit = is_32 or is_windows
def bytesio_helper():
return (BytesIO(bytearray(b'')),
@@ -254,25 +256,41 @@ def test_coverage(self):
[[],[],[],[],[],[],[],[],[],[]],
[0,0,0,0,0,0,0,0,0,0]],
[('l',[-1]),
- [[-1],[-159],[-40351],[-10263967],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849]],
- [0,1,2,3,4,4,4,4,4,4]],
+ [[-1],[-159],[-40351],[-10263967],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849]]
+ if is_long32bit else
+ [[big(-1)],[big(-159)],[big(-40351)],[big(-10263967)],[big(-2610732447)],[big(-664035696031)],[big(-168889314745759)],[big(-42953085774765471)],[big(7523094288207667809)],[big(7523094288207667809)]],
+ [0,1,2,3,4,4,4,4,4,4]
+ if is_long32bit else
+ [0,1,2,3,4,5,6,7,8,8]],
[('l',[1,-99,47]),
- [[1,-99,47],[97,-99,47],[25185,-99,47],[6513249,-99,47],[1684234849,-99,47],[1684234849,-155,47],[1684234849,-39323,47],[1684234849,-10000795,47],[1684234849,1751606885,47],[1684234849,1751606885,105]],
+ [[1,-99,47],[97,-99,47],[25185,-99,47],[6513249,-99,47],[1684234849,-99,47],[1684234849,-155,47],[1684234849,-39323,47],[1684234849,-10000795,47],[1684234849,1751606885,47],[1684234849,1751606885,105]]
+ if is_long32bit else
+ [[big(1),big(-99),big(47)],[big(97),big(-99),big(47)],[big(25185),big(-99),big(47)],[big(6513249),big(-99),big(47)],[big(1684234849),big(-99),big(47)],[big(435475931745),big(-99),big(47)],[big(112585661964897),big(-99),big(47)],[big(29104508263162465),big(-99),big(47)],[big(7523094288207667809),big(-99),big(47)],[big(7523094288207667809),big(-151),big(47)]],
[0,1,2,3,4,5,6,7,8,9]],
[('l',[1,-99,47,48]),
- [[1,-99,47,48],[97,-99,47,48],[25185,-99,47,48],[6513249,-99,47,48],[1684234849,-99,47,48],[1684234849,-155,47,48],[1684234849,-39323,47,48],[1684234849,-10000795,47,48],[1684234849,1751606885,47,48],[1684234849,1751606885,105,48]],
+ [[1,-99,47,48],[97,-99,47,48],[25185,-99,47,48],[6513249,-99,47,48],[1684234849,-99,47,48],[1684234849,-155,47,48],[1684234849,-39323,47,48],[1684234849,-10000795,47,48],[1684234849,1751606885,47,48],[1684234849,1751606885,105,48]]
+ if is_long32bit else
+ [[big(1),big(-99),big(47),big(48)],[big(97),big(-99),big(47),big(48)],[big(25185),big(-99),big(47),big(48)],[big(6513249),big(-99),big(47),big(48)],[big(1684234849),big(-99),big(47),big(48)],[big(435475931745),big(-99),big(47),big(48)],[big(112585661964897),big(-99),big(47),big(48)],[big(29104508263162465),big(-99),big(47),big(48)],[big(7523094288207667809),big(-99),big(47),big(48)],[big(7523094288207667809),big(-151),big(47),big(48)]],
[0,1,2,3,4,5,6,7,8,9]],
[('l',[1,-99,47,48,49]),
- [[1,-99,47,48,49],[97,-99,47,48,49],[25185,-99,47,48,49],[6513249,-99,47,48,49],[1684234849,-99,47,48,49],[1684234849,-155,47,48,49],[1684234849,-39323,47,48,49],[1684234849,-10000795,47,48,49],[1684234849,1751606885,47,48,49],[1684234849,1751606885,105,48,49]],
+ [[1,-99,47,48,49],[97,-99,47,48,49],[25185,-99,47,48,49],[6513249,-99,47,48,49],[1684234849,-99,47,48,49],[1684234849,-155,47,48,49],[1684234849,-39323,47,48,49],[1684234849,-10000795,47,48,49],[1684234849,1751606885,47,48,49],[1684234849,1751606885,105,48,49]]
+ if is_long32bit else
+ [[big(1),big(-99),big(47),big(48),big(49)],[big(97),big(-99),big(47),big(48),big(49)],[big(25185),big(-99),big(47),big(48),big(49)],[big(6513249),big(-99),big(47),big(48),big(49)],[big(1684234849),big(-99),big(47),big(48),big(49)],[big(435475931745),big(-99),big(47),big(48),big(49)],[big(112585661964897),big(-99),big(47),big(48),big(49)],[big(29104508263162465),big(-99),big(47),big(48),big(49)],[big(7523094288207667809),big(-99),big(47),big(48),big(49)],[big(7523094288207667809),big(-151),big(47),big(48),big(49)]],
[0,1,2,3,4,5,6,7,8,9]],
[('L',),
[[],[],[],[],[],[],[],[],[],[]],
[0,0,0,0,0,0,0,0,0,0]],
[('L',[big(100000000)]),
- [[big(100000000)],[big(100000097)],[big(99967585)],[big(90399329)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)]],
- [0,1,2,3,4,4,4,4,4,4]],
+ [[big(100000000)],[big(100000097)],[big(99967585)],[big(90399329)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)]]
+ if is_long32bit else
+ [[big(100000000)],[big(100000097)],[big(99967585)],[big(90399329)],[big(1684234849)],[big(435475931745)],[big(112585661964897)],[big(29104508263162465)],[big(7523094288207667809)],[big(7523094288207667809)]],
+ [0,1,2,3,4,4,4,4,4,4]
+ if is_long32bit else
+ [0,1,2,3,4,5,6,7,8,8]],
[('L',[big(1),big(99),big(47)]),
- [[big(1),big(99),big(47)],[big(97),big(99),big(47)],[big(25185),big(99),big(47)],[big(6513249),big(99),big(47)],[big(1684234849),big(99),big(47)],[big(1684234849),big(101),big(47)],[big(1684234849),big(26213),big(47)],[big(1684234849),big(6776421),big(47)],[big(1684234849),big(1751606885),big(47)],[big(1684234849),big(1751606885),big(105)]],
+ [[big(1),big(99),big(47)],[big(97),big(99),big(47)],[big(25185),big(99),big(47)],[big(6513249),big(99),big(47)],[big(1684234849),big(99),big(47)],[big(1684234849),big(101),big(47)],[big(1684234849),big(26213),big(47)],[big(1684234849),big(6776421),big(47)],[big(1684234849),big(1751606885),big(47)],[big(1684234849),big(1751606885),big(105)]]
+ if is_long32bit else
+ [[big(1),big(99),big(47)],[big(97),big(99),big(47)],[big(25185),big(99),big(47)],[big(6513249),big(99),big(47)],[big(1684234849),big(99),big(47)],[big(435475931745),big(99),big(47)],[big(112585661964897),big(99),big(47)],[big(29104508263162465),big(99),big(47)],[big(7523094288207667809),big(99),big(47)],[big(7523094288207667809),big(105),big(47)]],
[0,1,2,3,4,5,6,7,8,9]],
[('f',[]),
[[],[],[],[],[],[],[],[],[],[]],
@@ -298,7 +316,7 @@ def test_coverage(self):
[('d',[1.0,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996]),
[[1.0,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[1.0000000000000215,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[1.0000000000055922,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[1.0000000014462318,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[1.0000003739752616,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[1.0000966950812187,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[1.0249990388312187,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[0.002856443435217224,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[8.5408832230361244e+194,3.1400000000000001,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996],[8.5408832230361244e+194,3.140000000000033,0.99734343339999998,1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5,6.5999999999999996]],
[0,1,2,3,4,5,6,7,8,9]],
- ]
+ ]
for a_params, a_expected, b_expected in readinto_cases:
b_list = bytesio_helper()
@@ -309,7 +327,7 @@ def test_coverage(self):
self.assertEqual(b.readinto(a),
b_expected[i])
self.assertEqual(a.tolist(),
- a_expected[i])
+ a_expected[i], "Failed on case %s" % str(a_params))
def test_ipy2_gh711(self):
"""https://github.com/IronLanguages/ironpython2/issues/711"""
diff --git a/tests/suite/modules/io_related/test__fileio.py b/tests/suite/modules/io_related/test__fileio.py
index 07cb8a04b..eb75696de 100644
--- a/tests/suite/modules/io_related/test__fileio.py
+++ b/tests/suite/modules/io_related/test__fileio.py
@@ -13,7 +13,9 @@
from _io import FileIO
-from iptest import IronPythonTestCase, run_test
+from iptest import IronPythonTestCase, big, is_32, is_windows, run_test
+
+is_long32bit = is_32 or is_windows
def bytesio_helper():
return (bytes(bytearray(b'')),
@@ -366,27 +368,47 @@ def test_coverage(self):
#http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=24317
[('l',[1,2]),
- [[1,2],[97,2],[25185,2],[6513249,2],[1684234849,2],[1684234849,101],[1684234849,26213],[1684234849,6776421],[1684234849,1751606885],[1684234849,1751606885]],
- [0,1,2,3,4,5,6,7,8,8]],
+ [[1,2],[97,2],[25185,2],[6513249,2],[1684234849,2],[1684234849,101],[1684234849,26213],[1684234849,6776421],[1684234849,1751606885],[1684234849,1751606885]]
+ if is_long32bit else
+ [[big(1),big(2)],[big(97),big(2)],[big(25185),big(2)],[big(6513249),big(2)],[big(1684234849),big(2)],[big(435475931745),big(2)],[big(112585661964897),big(2)],[big(29104508263162465),big(2)],[big(7523094288207667809),big(2)],[big(7523094288207667809),big(105)]],
+ [0,1,2,3,4,5,6,7,8,8]
+ if is_long32bit else
+ [0,1,2,3,4,5,6,7,8,9]],
[('l',[-1]),
- [[-1],[-159],[-40351],[-10263967],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849]],
- [0,1,2,3,4,4,4,4,4,4]],
+ [[-1],[-159],[-40351],[-10263967],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849]]
+ if is_long32bit else
+ [[big(-1)],[big(-159)],[big(-40351)],[big(-10263967)],[big(-2610732447)],[big(-664035696031)],[big(-168889314745759)],[big(-42953085774765471)],[big(7523094288207667809)],[big(7523094288207667809)]],
+ [0,1,2,3,4,4,4,4,4,4]
+ if is_long32bit else
+ [0,1,2,3,4,5,6,7,8,8]],
[('l',[1,-99,47]),
- [[1,-99,47],[97,-99,47],[25185,-99,47],[6513249,-99,47],[1684234849,-99,47],[1684234849,-155,47],[1684234849,-39323,47],[1684234849,-10000795,47],[1684234849,1751606885,47],[1684234849,1751606885,105]],
+ [[1,-99,47],[97,-99,47],[25185,-99,47],[6513249,-99,47],[1684234849,-99,47],[1684234849,-155,47],[1684234849,-39323,47],[1684234849,-10000795,47],[1684234849,1751606885,47],[1684234849,1751606885,105]]
+ if is_long32bit else
+ [[big(1),big(-99),big(47)],[big(97),big(-99),big(47)],[big(25185),big(-99),big(47)],[big(6513249),big(-99),big(47)],[big(1684234849),big(-99),big(47)],[big(435475931745),big(-99),big(47)],[big(112585661964897),big(-99),big(47)],[big(29104508263162465),big(-99),big(47)],[big(7523094288207667809),big(-99),big(47)],[big(7523094288207667809),big(-151),big(47)]],
[0,1,2,3,4,5,6,7,8,9]],
[('l',[1,-99,47,48]),
- [[1,-99,47,48],[97,-99,47,48],[25185,-99,47,48],[6513249,-99,47,48],[1684234849,-99,47,48],[1684234849,-155,47,48],[1684234849,-39323,47,48],[1684234849,-10000795,47,48],[1684234849,1751606885,47,48],[1684234849,1751606885,105,48]],
+ [[1,-99,47,48],[97,-99,47,48],[25185,-99,47,48],[6513249,-99,47,48],[1684234849,-99,47,48],[1684234849,-155,47,48],[1684234849,-39323,47,48],[1684234849,-10000795,47,48],[1684234849,1751606885,47,48],[1684234849,1751606885,105,48]]
+ if is_long32bit else
+ [[big(1),big(-99),big(47),big(48)],[big(97),big(-99),big(47),big(48)],[big(25185),big(-99),big(47),big(48)],[big(6513249),big(-99),big(47),big(48)],[big(1684234849),big(-99),big(47),big(48)],[big(435475931745),big(-99),big(47),big(48)],[big(112585661964897),big(-99),big(47),big(48)],[big(29104508263162465),big(-99),big(47),big(48)],[big(7523094288207667809),big(-99),big(47),big(48)],[big(7523094288207667809),big(-151),big(47),big(48)]],
[0,1,2,3,4,5,6,7,8,9]],
[('l',[1,-99,47,48,49]),
- [[1,-99,47,48,49],[97,-99,47,48,49],[25185,-99,47,48,49],[6513249,-99,47,48,49],[1684234849,-99,47,48,49],[1684234849,-155,47,48,49],[1684234849,-39323,47,48,49],[1684234849,-10000795,47,48,49],[1684234849,1751606885,47,48,49],[1684234849,1751606885,105,48,49]],
+ [[1,-99,47,48,49],[97,-99,47,48,49],[25185,-99,47,48,49],[6513249,-99,47,48,49],[1684234849,-99,47,48,49],[1684234849,-155,47,48,49],[1684234849,-39323,47,48,49],[1684234849,-10000795,47,48,49],[1684234849,1751606885,47,48,49],[1684234849,1751606885,105,48,49]]
+ if is_long32bit else
+ [[big(1),big(-99),big(47),big(48),big(49)],[big(97),big(-99),big(47),big(48),big(49)],[big(25185),big(-99),big(47),big(48),big(49)],[big(6513249),big(-99),big(47),big(48),big(49)],[big(1684234849),big(-99),big(47),big(48),big(49)],[big(435475931745),big(-99),big(47),big(48),big(49)],[big(112585661964897),big(-99),big(47),big(48),big(49)],[big(29104508263162465),big(-99),big(47),big(48),big(49)],[big(7523094288207667809),big(-99),big(47),big(48),big(49)],[big(7523094288207667809),big(-151),big(47),big(48),big(49)]],
[0,1,2,3,4,5,6,7,8,9]],
#http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=24318
- [('L',[100000000]),
- [[100000000],[100000097],[99967585],[90399329],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849],[1684234849]],
- [0,1,2,3,4,4,4,4,4,4]],
- [('L',[1,99,47]),
- [[1,99,47],[97,99,47],[25185,99,47],[6513249,99,47],[1684234849,99,47],[1684234849,101,47],[1684234849,26213,47],[1684234849,6776421,47],[1684234849,1751606885,47],[1684234849,1751606885,105]],
+ [('L',[big(100000000)]),
+ [[big(100000000)],[big(100000097)],[big(99967585)],[big(90399329)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)],[big(1684234849)]]
+ if is_long32bit else
+ [[big(100000000)],[big(100000097)],[big(99967585)],[big(90399329)],[big(1684234849)],[big(435475931745)],[big(112585661964897)],[big(29104508263162465)],[big(7523094288207667809)],[big(7523094288207667809)]],
+ [0,1,2,3,4,4,4,4,4,4]
+ if is_long32bit else
+ [0,1,2,3,4,5,6,7,8,8]],
+ [('L',[big(1),big(99),big(47)]),
+ [[big(1),big(99),big(47)],[big(97),big(99),big(47)],[big(25185),big(99),big(47)],[big(6513249),big(99),big(47)],[big(1684234849),big(99),big(47)],[big(1684234849),big(101),big(47)],[big(1684234849),big(26213),big(47)],[big(1684234849),big(6776421),big(47)],[big(1684234849),big(1751606885),big(47)],[big(1684234849),big(1751606885),big(105)]]
+ if is_long32bit else
+ [[big(1),big(99),big(47)],[big(97),big(99),big(47)],[big(25185),big(99),big(47)],[big(6513249),big(99),big(47)],[big(1684234849),big(99),big(47)],[big(435475931745),big(99),big(47)],[big(112585661964897),big(99),big(47)],[big(29104508263162465),big(99),big(47)],[big(7523094288207667809),big(99),big(47)],[big(7523094288207667809),big(105),big(47)]],
[0,1,2,3,4,5,6,7,8,9]],
#http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=24319
@@ -425,7 +447,7 @@ def test_coverage(self):
self.assertEqual(f.readinto(a),
f_expected[i])
self.assertEqual(a.tolist(),
- a_expected[i])
+ a_expected[i], "Failed on case %s" % str(a_params))
# try with bytearray as well - https://github.com/IronLanguages/ironpython2/issues/713
f.seek(0)
diff --git a/tests/suite/modules/type_related/test__struct.py b/tests/suite/modules/type_related/test__struct.py
index 6d36c3b0f..f8eec4661 100644
--- a/tests/suite/modules/type_related/test__struct.py
+++ b/tests/suite/modules/type_related/test__struct.py
@@ -5,7 +5,9 @@
import _struct
import sys
-from iptest import IronPythonTestCase, is_64, is_cli, is_cpython, run_test
+from iptest import IronPythonTestCase, is_32, is_64, is_cli, is_cpython, is_windows, run_test
+
+is_long32bit = is_32 or is_windows
def pack(f, *v):
return _struct.Struct(f).pack(*v)
@@ -78,16 +80,16 @@ def test_cp3092(self):
def test_cp9347(self):
temp_list = [("2xB", b'\x00\x00\xff', 255),
- ("4s4x", b'AAAA\x00\x00\x00\x00', b"AAAA"),
- ("x", b'\x00'),
- ("ix", b'\x01\x00\x00\x00\x00', 1),
- ("ix", b'\x01\x00\x00\x80\x00', -(2**(32-1)-1)),
- ("xI", b'\x00\x00\x00\x00\xff\xff\xff\xff', 2**32-1),
- ("xlx", b'\x00\x00\x00\x00x\xec\xff\xff\x00', -5000),
- ("LxL", b'~\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00', 126, 126),
- ("LxxL", b'~\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00', 126, 126),
- ("32xLL", b'\x00' *32 + b'~\x00\x00\x00~\x00\x00\x00', 126, 126),
- ("LxL8xLL", b'~\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00' + b'\x00'*8 + b'~\x00\x00\x00'*2, 126, 126, 126, 126),
+ ("4s4x", b'AAAA\x00\x00\x00\x00', b"AAAA"),
+ ("x", b'\x00'),
+ ("ix", b'\x01\x00\x00\x00\x00', 1),
+ ("ix", b'\x01\x00\x00\x80\x00', -(2**(32-1)-1)),
+ ("xI", b'\x00\x00\x00\x00\xff\xff\xff\xff', 2**32-1),
+ ("xix", b'\x00\x00\x00\x00x\xec\xff\xff\x00', -5000),
+ ("IxI", b'~\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00', 126, 126),
+ ("IxxI", b'~\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00', 126, 126),
+ ("32xII", b'\x00' *32 + b'~\x00\x00\x00~\x00\x00\x00', 126, 126),
+ ("IxI8xII", b'~\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00' + b'\x00'*8 + b'~\x00\x00\x00'*2, 126, 126, 126, 126),
]
for stuff in temp_list:
@@ -96,7 +98,7 @@ def test_cp9347(self):
params = stuff[2:]
actual = pack(format, *params)
- self.assertEqual(expected_val, actual)
+ self.assertEqual(expected_val, actual, "Test failed for format: " + format)
self.assertEqual(unpack(format, actual),
params)
@@ -168,7 +170,10 @@ def test_calcsize_alignment(self):
for x in struct_format:
for y in struct_format:
temp_str = str(x) + str(y)
- expected_size = expected[temp_str]
+ if is_long32bit:
+ expected_size = expected[temp_str]
+ else:
+ expected_size = expected[temp_str.replace("l", "q").replace("L", "Q")]
if is_64:
if x == "P": expected_size = min(expected_size + 4, 16)
if y == "P": expected_size = 16
@@ -181,7 +186,7 @@ def test_new_init(self):
for x in (_struct.Struct.__new__(_struct.Struct), _struct.Struct.__new__(_struct.Struct, a = 2)):
# state of uninitialized object...
self.assertEqual(x.size, -1)
- self.assertEqual(x.format, None if is_cli or is_cpython and sys.version_info < (3,7) else '\x00\x00\x00\x00\x00\x00\x00')
+ self.assertEqual(x.format, None if is_cli or is_cpython and sys.version_info < (3,7) else '\x00\x00\x00\x00\x00\x00\x00\x00')
self.assertRaisesMessage(_struct.error, "pack requires exactly -1 arguments" if is_cli else "pack expected -1 items for packing (got 0)", x.pack)
self.assertRaisesMessage(_struct.error, "unpack requires a bytes object of length -1" if is_cli or is_cpython and sys.version_info < (3,6) else "unpack requires a buffer of -1 bytes", x.unpack, b'')
diff --git a/tests/suite/modules/type_related/test_array.py b/tests/suite/modules/type_related/test_array.py
index 848c4343b..55fe4b111 100644
--- a/tests/suite/modules/type_related/test_array.py
+++ b/tests/suite/modules/type_related/test_array.py
@@ -8,6 +8,7 @@
import array
import sys
+import pickle
from iptest import IronPythonTestCase, is_cli, is_mono, big, run_test
@@ -162,9 +163,14 @@ def test_array___init__(self):
self.assertEqual(a, b)
#--L
- a = array.array('L', b"\x12\x34\x45\x67")
- self.assertEqual(1, len(a))
- self.assertEqual(1732588562, a[0])
+ a = array.array('L', b"\x12\x34\x45\x67" * 2)
+ self.assertTrue(a.itemsize == 4 or a.itemsize == 8)
+ if a.itemsize == 4:
+ self.assertEqual(2, len(a))
+ self.assertEqual(1732588562, a[0])
+ else:
+ self.assertEqual(1, len(a))
+ self.assertEqual(7441411212946256914, a[0])
#--B
a = array.array('B', [0]) * big(2)
@@ -248,6 +254,17 @@ def test_array___reduce_ex__(self):
with self.assertRaises(TypeError):
x.__reduce_ex__()
+ def test_array_pickle(self):
+ int_codes = 'BHILQ'
+ for code in int_codes + int_codes.lower() + 'fd':
+ with self.subTest(code=code):
+ a = array.array(code, [1,2,3])
+ pickled = pickle.dumps(a)
+ b = pickle.loads(pickled)
+ self.assertEqual(a, b)
+ self.assertEqual(a.typecode, b.typecode)
+ self.assertEqual(a.itemsize, b.itemsize)
+
def test_array___repr__(self):
'''
TODO
@@ -454,9 +471,16 @@ def test_cp9348(self):
('i', b"\x12\x34\x45\x67") : "array('i', [1732588562])",
('I', b"\x12\x34\x45\x67") : "array('I', [1732588562])",
('I', b"\x01\x00\x00\x00") : "array('I', [1])",
- ('l', b"\x12\x34\x45\x67") : "array('l', [1732588562])",
- ('L', b"\x12\x34\x45\x67") : "array('L', [1732588562])",
+ ('q', b"\x12\x34\x45\x67\x89\xab\xcd\xef") : "array('q', [-1167088121787632622])",
+ ('Q', b"\x12\x34\x45\x67\x89\xab\xcd\xef") : "array('Q', [17279655951921918994])",
}
+ if array.array('L').itemsize == 4:
+ test_cases[('l', b"\x12\x34\x45\x67")] = "array('l', [1732588562])"
+ test_cases[('L', b"\x12\x34\x45\x67")] = "array('L', [1732588562])"
+ else:
+ test_cases[('l', b"\x12\x34\x45\x67\x89\xab\xcd\xef")] = "array('l', [-1167088121787632622])"
+ test_cases[('L', b"\x12\x34\x45\x67\x89\xab\xcd\xef")] = "array('L', [17279655951921918994])"
+
if is_cli: # https://github.com/IronLanguages/ironpython2/issues/102
test_cases[('d', b"\x12\x34\x45\x67\x12\x34\x45\x67")] = "array('d', [2.9522485325887698e+189])"
test_cases[('f', b"\x12\x34\x45\x67")] = "array('f', [9.3126672485384569e+23])"
diff --git a/tests/suite/modules/type_related/test_ctypes.py b/tests/suite/modules/type_related/test_ctypes.py
index baa14825e..8c3a2208e 100644
--- a/tests/suite/modules/type_related/test_ctypes.py
+++ b/tests/suite/modules/type_related/test_ctypes.py
@@ -8,6 +8,7 @@
from ctypes import *
from array import array
+from struct import calcsize
import sys
import gc
import unittest
@@ -177,13 +178,7 @@ def test_bitfield_bool_truthy(self):
class Test(Structure):
_fields_ = [("x", c_bool, 1)]
- class myindex:
- def __init__(self, value):
- self.value = value
- def __index__(self):
- return self.value
-
- for val in (None, "", "False", "True", "0", "1", 0, 1, 2, 0.0, 1.0, [], (), {}, object(), myindex(0), myindex(1)):
+ for val in (None, "", "False", "True", "0", "1", 0, 1, 2, 0.0, 1.0, [], (), {}, object(), MyIndex(0), MyIndex(1)):
with self.subTest(val=val):
self.assertIs(Test(val).x, bool(val))
@@ -191,24 +186,18 @@ def __index__(self):
s.x = val
self.assertIs(s.x, bool(val))
- def test_bitfield_long(self):
- """Tests for bitfields of type c_long"""
+ def test_bitfield_int(self):
+ """Tests for bitfields of type c_int"""
class Test(Structure):
- _fields_ = [("x", c_long, 16), ("y", c_long, 16), ("z", c_long, 32)]
-
- class myindex:
- def __init__(self, value):
- self.value = value
- def __index__(self):
- return self.value
+ _fields_ = [("x", c_int, 16), ("y", c_int, 16), ("z", c_int, 32)]
self.assertEqual(Test(0x1234).x, 0x1234)
self.assertEqual(Test(big(0x1234)).x, 0x1234)
self.assertEqual(Test(myint(0x1234)).x, 0x1234)
self.assertEqual(Test(True).x, 1)
if is_cli or sys.version_info >= (3, 8):
- self.assertEqual(Test(myindex(0x1234)).x, 0x1234)
+ self.assertEqual(Test(MyIndex(0x1234)).x, 0x1234)
if is_cli or sys.version_info >= (3, 10):
msg = "'float' object cannot be interpreted as an integer"
else:
@@ -218,10 +207,11 @@ def __index__(self):
with self.assertRaisesMessage(ValueError, "number of bits invalid for bit field"):
class Test(Structure):
_fields_ = [("x", c_int, 0)]
-
- self.assertEqual(repr(Test.x), "")
- self.assertEqual(repr(Test.y), "")
- self.assertEqual(repr(Test.z), "")
+ # if c_long and c_int are the same size, c_long is used
+ typename = "c_long" if calcsize('l') == calcsize('i') else "c_int"
+ self.assertEqual(repr(Test.x), "".format(typename))
+ self.assertEqual(repr(Test.y), "".format(typename))
+ self.assertEqual(repr(Test.z), "".format(typename))
self.assertEqual((Test.x.offset, Test.x.size), (0, (16 << 16) + 0))
self.assertEqual((Test.y.offset, Test.y.size), (0, (16 << 16) + 16))
diff --git a/tests/suite/test_memoryview.py b/tests/suite/test_memoryview.py
index b8704a6c7..45004b8f3 100644
--- a/tests/suite/test_memoryview.py
+++ b/tests/suite/test_memoryview.py
@@ -9,7 +9,9 @@
import unittest
import warnings
-from iptest import run_test, is_mono, is_cli, is_64
+from iptest import run_test, is_mono, is_cli, is_32, is_64, is_windows
+
+is_long32bit = is_32 or is_windows
class SliceTests(unittest.TestCase):
def testGet(self):
@@ -191,7 +193,7 @@ def test_equality_structural(self):
self.assertFalse(mv_i == mv)
self.assertFalse(mv_i == mv_h)
mv_L = mv.cast('L')
- self.assertTrue(mv_i == mv_L)
+ self.assertEqual(mv_i == mv_L, is_long32bit)
mv_f = mv.cast('f')
self.assertFalse(mv_i == mv_f)
@@ -206,7 +208,7 @@ def test_equality_structural(self):
mv_P = mv.cast('P')
self.assertFalse(mv_P == mv_i)
- self.assertFalse(mv_P == mv_L)
+ self.assertEqual(mv_P == mv_L, not is_long32bit)
self.assertTrue(mv_P == mv_q)
self.assertTrue(mv_P == mv_Q)
diff --git a/tests/suite/test_regressions.py b/tests/suite/test_regressions.py
index b9ab08ab9..37d6ce28d 100644
--- a/tests/suite/test_regressions.py
+++ b/tests/suite/test_regressions.py
@@ -18,7 +18,9 @@ def test_cp1234(): ...
import sys
import unittest
-from iptest import IronPythonTestCase, is_cli, is_mono, is_netcoreapp, is_netcoreapp21, is_posix, run_test, skipUnlessIronPython, stdout_trapper
+from iptest import IronPythonTestCase, is_32, is_cli, is_mono, is_netcoreapp, is_netcoreapp21, is_windows, is_posix, run_test, skipUnlessIronPython, stdout_trapper
+
+is_long32bit = is_32 or is_windows
class RegressionTest(IronPythonTestCase):
@@ -229,18 +231,22 @@ def __int__(self):
andCalled = False
for code in ['L', 'I']:
- self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, 0x100000000)
+ if code != 'L' or is_long32bit:
+ self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, 0x100000000)
self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, -1)
for code in ['l', 'i', 'h', 'H', 'B', 'b']:
- self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, 0x80000000)
- self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, -0x80000001)
+ if code != 'l' or is_long32bit:
+ self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, 0x80000000)
+ self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, -0x80000001)
- self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct('Q').pack, 0x10000000000000000)
- self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct('Q').pack, -1)
+ for code in ['L', 'Q']:
+ self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, 0x10000000000000000)
+ self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, -1)
- self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct('q').pack, 0x8000000000000000)
- self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct('q').pack, -0x8000000000000001)
+ for code in ['l', 'q']:
+ self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, 0x8000000000000000)
+ self.assertRaisesRegex(_struct.error, "argument out of range", _struct.Struct(code).pack, -0x8000000000000001)
self.assertRaisesRegex(_struct.error, r"ushort format requires 0 <= number .*", _struct.Struct('H').pack, 0x10000)
self.assertRaisesRegex(_struct.error, r"ushort format requires 0 <= number .*", _struct.Struct('H').pack, -1)
diff --git a/tests/suite/test_struct.py b/tests/suite/test_struct.py
index b08651f6b..819838f70 100644
--- a/tests/suite/test_struct.py
+++ b/tests/suite/test_struct.py
@@ -97,4 +97,22 @@ def test_iter_unpack(self):
# struct.error: iterative unpacking requires a buffer of a multiple of {N} bytes
self.assertRaises(struct.error, struct.iter_unpack, "h", b"\0")
+
+ def test_sizes(self):
+ # test sizes of standard struct types
+ for mode in ('<', '>', '=', '!'):
+ self.assertEqual(struct.calcsize(mode + 'b'), 1)
+ self.assertEqual(struct.calcsize(mode + 'B'), 1)
+ self.assertEqual(struct.calcsize(mode + 'h'), 2)
+ self.assertEqual(struct.calcsize(mode + 'H'), 2)
+ self.assertEqual(struct.calcsize(mode + 'i'), 4)
+ self.assertEqual(struct.calcsize(mode + 'I'), 4)
+ self.assertEqual(struct.calcsize(mode + 'l'), 4)
+ self.assertEqual(struct.calcsize(mode + 'L'), 4)
+ self.assertEqual(struct.calcsize(mode + 'q'), 8)
+ self.assertEqual(struct.calcsize(mode + 'Q'), 8)
+ self.assertEqual(struct.calcsize(mode + 'f'), 4)
+ self.assertEqual(struct.calcsize(mode + 'd'), 8)
+
+
run_test(__name__)