Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18c7e9a

Browse files
author
Barton Cline
committed
* With Advanced Build Settings::Check for arithmetic overflow/underflow set, this is the only section that threw while running unittest.
1 parent 2ae4dbe commit 18c7e9a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pythonnet/src/runtime/converter.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,14 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
450450
if (Runtime.PyUnicode_GetSize(value) == 1) {
451451
op = Runtime.PyUnicode_AS_UNICODE(value);
452452
#if (!UCS4)
453-
result = (char)Marshal.ReadInt16(op);
453+
// 2011-01-02: Marshal as character array because the cast
454+
// result = (char)Marshal.ReadInt16(op); throws an OverflowException
455+
// on negative numbers with Check Overflow option set on the project
456+
Char[] buff = new Char[1];
457+
Marshal.Copy(op, buff, 0, 1);
458+
result = buff[0];
454459
#else
455-
// XXX is this correct?
460+
// XXX this is probably NOT correct?
456461
result = (char)Marshal.ReadInt32(op);
457462
#endif
458463
return true;

0 commit comments

Comments
 (0)