Skip to content

Commit 03bd232

Browse files
committed
Fix marshalling of short integers
1 parent bd54dfd commit 03bd232

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/core/IronPython.Modules/ModuleOps.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using IronPython.Runtime.Exceptions;
1818
using IronPython.Runtime.Operations;
1919
using IronPython.Runtime.Types;
20+
using System.Runtime.CompilerServices;
2021

2122
namespace IronPython.Modules {
2223
/// <summary>
@@ -526,12 +527,12 @@ public static int GetSignedInt(object value, object type) {
526527
throw PythonOps.TypeErrorForTypeMismatch("signed int", value);
527528
}
528529

529-
public static short GetUnsignedShort(object value, object type) {
530+
public static ushort GetUnsignedShort(object value, object type) {
530531
int? res = Converter.ImplicitConvertToInt32(value);
531532
if (res != null) {
532533
int iVal = res.Value;
533534
if (iVal >= ushort.MinValue && iVal <= ushort.MaxValue) {
534-
return (short)(ushort)iVal;
535+
return (ushort)iVal;
535536
}
536537
}
537538
if (PythonOps.TryGetBoundAttr(value, "_as_parameter_", out object asParam)) {
@@ -574,12 +575,12 @@ public static byte GetUnsignedByte(object value, object type) {
574575
throw PythonOps.TypeErrorForTypeMismatch("unsigned byte", value);
575576
}
576577

577-
public static byte GetSignedByte(object value, object type) {
578+
public static sbyte GetSignedByte(object value, object type) {
578579
int? res = Converter.ImplicitConvertToInt32(value);
579580
if (res != null) {
580581
int iVal = res.Value;
581582
if (iVal >= sbyte.MinValue && iVal <= sbyte.MaxValue) {
582-
return (byte)(sbyte)iVal;
583+
return (sbyte)iVal;
583584
}
584585
}
585586

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ object INativeType.SetValue(MemoryHolder/*!*/ owner, int offset, object value) {
251251
switch (_type) {
252252
case SimpleTypeKind.Boolean: owner.WriteByte(offset, ModuleOps.GetBoolean(value, this)); break;
253253
case SimpleTypeKind.Char: owner.WriteByte(offset, ModuleOps.GetChar(value, this)); break;
254-
case SimpleTypeKind.SignedByte: owner.WriteByte(offset, ModuleOps.GetSignedByte(value, this)); break;
254+
case SimpleTypeKind.SignedByte: owner.WriteByte(offset, (byte)ModuleOps.GetSignedByte(value, this)); break;
255255
case SimpleTypeKind.UnsignedByte: owner.WriteByte(offset, ModuleOps.GetUnsignedByte(value, this)); break;
256256
case SimpleTypeKind.WChar: owner.WriteInt16(offset, (short)ModuleOps.GetWChar(value, this)); break;
257257
case SimpleTypeKind.SignedShort: owner.WriteInt16(offset, ModuleOps.GetSignedShort(value, this), _swap); break;
258-
case SimpleTypeKind.UnsignedShort: owner.WriteInt16(offset, ModuleOps.GetUnsignedShort(value, this), _swap); break;
258+
case SimpleTypeKind.UnsignedShort: owner.WriteInt16(offset, (short)ModuleOps.GetUnsignedShort(value, this), _swap); break;
259259
case SimpleTypeKind.VariantBool: owner.WriteInt16(offset, (short)ModuleOps.GetVariantBool(value, this), _swap); break;
260260
case SimpleTypeKind.SignedInt: owner.WriteInt32(offset, ModuleOps.GetSignedInt(value, this), _swap); break;
261261
case SimpleTypeKind.UnsignedInt: owner.WriteInt32(offset, ModuleOps.GetUnsignedInt(value, this), _swap); break;

0 commit comments

Comments
 (0)