Skip to content

overloading - more fixes for wordpad.py #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/wordpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def InitializeComponent(self):
self.richTextBox.TabIndex = 0
self.richTextBox.AutoSize = 1
self.richTextBox.ScrollBars = WinForms.RichTextBoxScrollBars.ForcedBoth
self.richTextBox.Font = System.Drawing.Font("Tahoma", 10)
self.richTextBox.Font = System.Drawing.Font("Tahoma", 10.0)
self.richTextBox.AcceptsTab = 1
self.richTextBox.Location = System.Drawing.Point(0, 0)

Expand Down
28 changes: 28 additions & 0 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ private Converter() {}
static NumberFormatInfo nfi;
static Type objectType;
static Type stringType;
static Type singleType;
static Type doubleType;
static Type decimalType;
static Type int16Type;
static Type int32Type;
static Type int64Type;
static Type flagsType;
Expand All @@ -40,9 +43,12 @@ static Converter () {
nfi = NumberFormatInfo.InvariantInfo;
objectType = typeof(Object);
stringType = typeof(String);
int16Type = typeof(Int16);
int32Type = typeof(Int32);
int64Type = typeof(Int64);
singleType = typeof(Single);
doubleType = typeof(Double);
decimalType = typeof(Decimal);
flagsType = typeof(FlagsAttribute);
boolType = typeof(Boolean);
typeType = typeof(Type);
Expand Down Expand Up @@ -73,6 +79,28 @@ internal static Type GetTypeByAlias(IntPtr op) {
return null;
}

internal static IntPtr GetPythonTypeByAlias(Type op)
{
if (op == stringType) {
return Runtime.PyUnicodeType;
}
else if ((op == int16Type) ||
(op == int32Type)) {
return Runtime.PyIntType;
}
else if (op == int64Type) {
return Runtime.PyLongType;
}
else if ((op == doubleType) ||
(op == singleType)) {
return Runtime.PyFloatType;
}
else if (op == boolType) {
return Runtime.PyBoolType;
}
return IntPtr.Zero;
}


//====================================================================
// Return a Python object for the given native object, converting
Expand Down
49 changes: 34 additions & 15 deletions src/runtime/methodbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
else {
_methods = GetMethods();
}
Type type;
Type clrtype;
for (int i = 0; i < _methods.Length; i++) {
MethodBase mi = _methods[i];

Expand Down Expand Up @@ -295,34 +295,53 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
// this logic below handles cases when multiple overloading methods
// are ambiguous, hence comparison between Python and CLR types
// is necessary
type = null;

if (_methods.Length>1) {
IntPtr pyoptype = IntPtr.Zero;
clrtype = null;
IntPtr pyoptype;
if (_methods.Length > 1) {
pyoptype = IntPtr.Zero;
pyoptype = Runtime.PyObject_Type(op);
Exceptions.Clear();
if (pyoptype != IntPtr.Zero) { }
type = Converter.GetTypeByAlias(pyoptype);
Runtime.Decref(pyoptype);
if (pyoptype != IntPtr.Zero) {
clrtype = Converter.GetTypeByAlias(pyoptype);
}
Runtime.Decref(pyoptype);
}


if (type != null) {
if (pi[n].ParameterType != type) {
margs = null;
break;
if (clrtype != null) {
if (pi[n].ParameterType != clrtype) {
IntPtr pytype = Converter.GetPythonTypeByAlias(pi[n].ParameterType);
// does pytype require Decref?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a question? it's your code, you should understand it. Comments should help the people that come after you to understand the code, not raise questions about its correctness.

pyoptype = Runtime.PyObject_Type(op);
Exceptions.Clear();
if (pyoptype != IntPtr.Zero) {
if (pytype != pyoptype) {
Runtime.Decref(pyoptype);
margs = null;
break;
}
else {
clrtype = pi[n].ParameterType;
}
}
else {
Runtime.Decref(pyoptype);
margs = null;
break;
}
Runtime.Decref(pyoptype);
}
}
else {
type = pi[n].ParameterType;
clrtype = pi[n].ParameterType;
}

if (pi[n].IsOut || type.IsByRef)
if (pi[n].IsOut || clrtype.IsByRef)
{
outs++;
}

if (!Converter.ToManaged(op, type, out arg, false))
if (!Converter.ToManaged(op, clrtype, out arg, false))
{
Exceptions.Clear();
margs = null;
Expand Down