From Ravinder.Kareer at sungard.com Tue Dec 8 18:46:05 2009 From: Ravinder.Kareer at sungard.com (Ravinder.Kareer at sungard.com) Date: Tue, 8 Dec 2009 12:46:05 -0500 Subject: [Python.NET] python for net with python 2.6 Message-ID: All, We have been trying to use python for net compiled against python26 with a target framework of 2.0 and are getting a hard crash. .NET Runtime version 2.0.50727.4927 - Fatal Execution Engine Error (719D851A) (80131506) We are able to "import clr", "import System", but when you do something as basic as "s = System.String('a')" you get a hard crash. These commands were run from the pythonw.exe from the python26 directory. Your assistance in this matter would be greatly appreciated. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Thu Dec 10 22:21:36 2009 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 10 Dec 2009 21:21:36 +0000 Subject: [Python.NET] Help required in python In-Reply-To: <563e3b0f0911052119i152b0796vcbd9e2620c10a9a5@mail.gmail.com> References: <563e3b0f0911052119i152b0796vcbd9e2620c10a9a5@mail.gmail.com> Message-ID: <4B216660.70805@voidspace.org.uk> On 06/11/2009 05:19, Srikanth vardarajan wrote: > Hi, > I am a new to python. I have method in a phyton file. > The method looks like this: Hello Srikanth, You've accessed a question about IronPython on the Python.NET mailing list. Python.NET is actually a separate project. Please redirect your questions to the IronPython mailing list: http://lists.ironpython.com/listinfo.cgi/users-ironpython.com All the best, Michael Foord > class > > Srikanth(object): """A virtual pet""" def talk(self): print "Hi. I'm > an instance of class Critter." > > I want to call this method from C# class. I am using Ironphyton studio. > > Can you tell me how do i this. > > it would be great if you can reply as quick as possible. > > Regards > > Srikanth > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From snaury at gmail.com Fri Dec 11 17:05:59 2009 From: snaury at gmail.com (Alexey Borzenkov) Date: Fri, 11 Dec 2009 19:05:59 +0300 Subject: [Python.NET] python for net with python 2.6 In-Reply-To: References: Message-ID: On Tue, Dec 8, 2009 at 8:46 PM, wrote: > We have been trying to use python for net compiled against python26 with a > target framework of 2.0 and are getting a hard crash. > > .NET Runtime version 2.0.50727.4927 - Fatal Execution Engine Error > (719D851A) (80131506) Can you please try with this patch: http://git.kitsu.ru/patched/pythonnet.git?a=commitdiff;h=a667bc8b29744a4baafaccc3806d19830a7bdeeb > We are able to ?import clr?, ?import System?, but when you do something as > basic as ?s = System.String(?a?)? you get a hard crash. > > These commands were run from the pythonw.exe from the python26 directory. I compiled clr with the above patch a very long time ago and I just checked in python.exe (not pythonw.exe since it doesn't show console... not sure what you meant) and these don't cause any crashes for me (Python 2.6.4). Make sure that you replace all PYTHON25 defines with PYTHON26 and there's a typo in one of source files that expects Python26 defined instead of PYTHON26. That's what the above patch fixes. From cgagnon at zindagigames.com Tue Dec 15 04:02:12 2009 From: cgagnon at zindagigames.com (Chris Gagnon) Date: Mon, 14 Dec 2009 19:02:12 -0800 Subject: [Python.NET] Why are default constructors called on exceptions? Message-ID: <826d5c730912141902i103283etf7e0ab205f648758@mail.gmail.com> Consider this C# library namespace MyLib > { > public class CXDoc > { > // Construction > public CXDoc(string sPath) > { > XmlDocument oDoc = new XmlDocument(); > oDoc.Load(sPath); > } > public CXDoc() > { > throw new Exception("Deprecated constructor."); > } > } > } > Now this script >>> import clr >>> clr.AddReference("System") >>> from System import * >>> clr.AddReference("System.Data") >>> from System.Data import * >>> clr.AddReference("System.Xml") >>> from System.Xml import * >>> clr.AddReference("MyLib") >>> >>> import MyLib >>> from MyLib import * Ready to go! >>> testI1 = MyLib.CXDoc("path that does exist") >>> Yeah all worked fine! >>> testI2 = MyLib.CXDoc("path that dosn't exist") Traceback (most recent call last): File "", line 1, in System.Exception: Deprecated constructor. at MyLib.CXDoc..ctor() What happened! Well inside the constructor it hit an file not found exception of some such. Can someone explain why it hides that from me and calls the default constructor and shows me that exception. This seems like an unintuitive thing to do, and has made debugging a huge pain. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ravinder.Kareer at sungard.com Mon Dec 14 14:30:43 2009 From: Ravinder.Kareer at sungard.com (Kareer, Ravinder) Date: Mon, 14 Dec 2009 08:30:43 -0500 Subject: [Python.NET] python for net with python 2.6 In-Reply-To: References: Message-ID: <709C86C0-15D5-4876-BC75-DEC8CAD140AF@sungard.com> Alex, Thanks a ton for your help. Your solution did the trick. Regards Bobby On Dec 11, 2009, at 11:06 AM, "Alexey Borzenkov" wrote: > On Tue, Dec 8, 2009 at 8:46 PM, wrote: >> We have been trying to use python for net compiled against python26 >> with a >> target framework of 2.0 and are getting a hard crash. >> >> .NET Runtime version 2.0.50727.4927 - Fatal Execution Engine Error >> (719D851A) (80131506) > > Can you please try with this patch: > http://git.kitsu.ru/patched/pythonnet.git?a=commitdiff;h=a667bc8b29744a4baafaccc3806d19830a7bdeeb > >> We are able to ?import clr?, ?import System?, but when you >> do something as >> basic as ?s = System.String(?a?)? you get a hard crash. >> >> These commands were run from the pythonw.exe from the python26 >> directory. > > I compiled clr with the above patch a very long time ago and I just > checked in python.exe (not pythonw.exe since it doesn't show > console... not sure what you meant) and these don't cause any crashes > for me (Python 2.6.4). Make sure that you replace all PYTHON25 defines > with PYTHON26 and there's a typo in one of source files that expects > Python26 defined instead of PYTHON26. That's what the above patch > fixes. > From snaury at gmail.com Wed Dec 16 22:39:29 2009 From: snaury at gmail.com (Alexey Borzenkov) Date: Thu, 17 Dec 2009 00:39:29 +0300 Subject: [Python.NET] Why are default constructors called on exceptions? In-Reply-To: <826d5c730912141902i103283etf7e0ab205f648758@mail.gmail.com> References: <826d5c730912141902i103283etf7e0ab205f648758@mail.gmail.com> Message-ID: On Tue, Dec 15, 2009 at 6:02 AM, Chris Gagnon wrote: >> namespace MyLib >> { >> ??? public class CXDoc >> ??? { >> ??? ??? // Construction >> ??? ??? public CXDoc(string sPath) >> ??? ??? { >> ??? ??? ??? XmlDocument oDoc = new XmlDocument(); >> ??? ??? ??? oDoc.Load(sPath); >> ??? ??? } >> ??? ??? public CXDoc() >> ??? ??? { >> ??? ??? ??? throw new Exception("Deprecated constructor."); >> ??? ??? } >> ??? } >> } > > ?Now this script > >>>> testI2 = MyLib.CXDoc("path that dosn't exist") > Traceback (most recent call last): > ? File "", line 1, in > System.Exception: Deprecated constructor. > ?? at MyLib.CXDoc..ctor() I think what happens here is a mistake in classobject.cs tp_new. If some exception happens during invoking of constructor, it just assumes that binding failed and tries to call constructor without argument in hopes that subclass's __init__ will initialize it. Here's some preliminary patch, though I didn't test it at all. You may try it and tell me if it helps. This patch ensures that we call "default" constructor only if we failed to bind. It won't happen if bound constructor throws some exception. diff --git a/src/runtime/classobject.cs b/src/runtime/classobject.cs index 4d70918..4a90c44 100644 --- a/src/runtime/classobject.cs +++ b/src/runtime/classobject.cs @@ -106,19 +106,7 @@ namespace Python.Runtime { Object obj = self.binder.InvokeRaw(IntPtr.Zero, args, kw); if (obj == null) { - // It is possible for __new__ to be invoked on construction - // of a Python subclass of a managed class, so args may - // reflect more args than are required to instantiate the - // class. So if we cant find a ctor that matches, we'll see - // if there is a default constructor and, if so, assume that - // any extra args are intended for the subclass' __init__. - - IntPtr eargs = Runtime.PyTuple_New(0); - obj = self.binder.InvokeRaw(IntPtr.Zero, eargs, kw); - Runtime.Decref(eargs); - if (obj == null) { - return IntPtr.Zero; - } + return IntPtr.Zero; } return CLRObject.GetInstHandle(obj, tp); diff --git a/src/runtime/constructorbinder.cs b/src/runtime/constructorbinder.cs index f7244c3..69d8c17 100644 --- a/src/runtime/constructorbinder.cs +++ b/src/runtime/constructorbinder.cs @@ -43,10 +43,23 @@ namespace Python.Runtime { Object result; if (binding == null) { - Exceptions.SetError(Exceptions.TypeError, - "no constructor matches given arguments" - ); - return null; + // It is possible for __new__ to be invoked on construction + // of a Python subclass of a managed class, so args may + // reflect more args than are required to instantiate the + // class. So if we cant find a ctor that matches, we'll see + // if there is a default constructor and, if so, assume that + // any extra args are intended for the subclass' __init__. + + IntPtr eargs = Runtime.PyTuple_New(0); + binding = this.Bind(inst, eargs, kw); + Runtime.Decref(eargs); + + if (binding == null) { + Exceptions.SetError(Exceptions.TypeError, + "no constructor matches given arguments" + ); + return null; + } } // Object construction is presumed to be non-blocking and fast From snaury at gmail.com Thu Dec 17 10:01:09 2009 From: snaury at gmail.com (Alexey Borzenkov) Date: Thu, 17 Dec 2009 12:01:09 +0300 Subject: [Python.NET] Why are default constructors called on exceptions? In-Reply-To: References: <826d5c730912141902i103283etf7e0ab205f648758@mail.gmail.com> Message-ID: On Thu, Dec 17, 2009 at 12:39 AM, Alexey Borzenkov wrote: > You may try it and tell me if it helps. Ok, I just checked it myself and it appears to work in your case. The patch is now in my tree: http://git.kitsu.ru/patched/pythonnet.git?a=commitdiff;h=995109e3ed27d6061dde5376f2968c9fbad894b7 I hope maintainers would take a look at this and maybe apply it in their tree. From cgagnon at zindagigames.com Thu Dec 17 18:16:32 2009 From: cgagnon at zindagigames.com (Chris Gagnon) Date: Thu, 17 Dec 2009 09:16:32 -0800 Subject: [Python.NET] Why are default constructors called on exceptions? In-Reply-To: References: <826d5c730912141902i103283etf7e0ab205f648758@mail.gmail.com> Message-ID: <826d5c730912170916h55557c7fjf74b46921ae01e9f@mail.gmail.com> Thanks Alexey, I haven't had a chance to try it yet, but I'm sure I'll be integrating your patch into our python.NET here. Cheers, Chris On Thu, Dec 17, 2009 at 1:01 AM, Alexey Borzenkov wrote: > On Thu, Dec 17, 2009 at 12:39 AM, Alexey Borzenkov > wrote: > > You may try it and tell me if it helps. > > Ok, I just checked it myself and it appears to work in your case. The > patch is now in my tree: > > > http://git.kitsu.ru/patched/pythonnet.git?a=commitdiff;h=995109e3ed27d6061dde5376f2968c9fbad894b7 > > I hope maintainers would take a look at this and maybe apply it in their > tree. > -------------- next part -------------- An HTML attachment was scrubbed... URL: