From darran.white at baml.com Wed Jan 18 13:55:25 2012 From: darran.white at baml.com (White, Darran M) Date: Wed, 18 Jan 2012 12:55:25 +0000 Subject: [Python.NET] type check in native C# after setting in Python.NET Message-ID: Hi, We`re calling .NET AvalonDock using Python.NET. Theres a callback called DockingManager.DeserializationCallback in AvalonDock. I`ve got this callback to be called by AvalonDock from Python.NET but nothing happens after its called. Looking at the AvalonDock code theres a type check contentToTransfer = e.Content as DockableContent; if (contentToTransfer != null) { .... } We`re setting the e.Content from Python.NET d = self._dockMgr.createDockableContent(ui.Label('Grid'), event.Name,closeable=True, infoTip='',docId=event.Name) e.Content = d e.Content is a when its in the Python but could the e.Content as DockableContent; still fail in the native C#? Thanks Darran ---------------------------------------------------------------------- This message w/attachments (message) is intended solely for the use of the intended recipient(s) and may contain information that is privileged, confidential or proprietary. If you are not an intended recipient, please notify the sender, and then please delete and destroy all copies and attachments, and be advised that any review or dissemination of, or the taking of any action in reliance on, the information contained in or attached to this message is prohibited. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Sender. Subject to applicable law, Sender may intercept, monitor, review and retain e-communications (EC) traveling through its networks/systems and may produce any such EC to regulators, law enforcement, in litigation and as required by law. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or free of errors or viruses. References to "Sender" are references to any subsidiary of Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this EC may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link: http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you consent to the foregoing. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skelly at passportcapital.com Fri Jan 20 22:37:55 2012 From: skelly at passportcapital.com (Scot Kelly) Date: Fri, 20 Jan 2012 21:37:55 +0000 Subject: [Python.NET] python for .net Message-ID: Re: Python for .NET. All, I have created a Clr example which instantiates and manipulates objects of type System.String. When I try to have it access the HelloWorld-esque object that I have written in VB.net python throws an error on my import statement. In the docs on "Python for .NET" there's no discussion on what form the .NET code must be in to be reachable, in terms of namespaces, modules and classes. Here's my code. I've tried encapsulating my class in Namespace and Module wrappers no avail. Perhaps the lack of a PublicKeyToken is an ssue. Any help you can provide would be greatly appreciated. Feedback... I thought the process was fairly simple. 0. The inclusion of python.exe in the .zip merits annotating as optional. 1. The readme should probably discuss the need to sys.path.append('c:\Python25\Lib\site-packages\Clr'). 2. I thought the filename, Python.Runtime.dll, was too generic. Is it within your abilities to name it more specifically, such as PythonForNet.Runtime.dll 3. There's no reference section for the methods of clr. (ex: what is the parameter to and usage of ListAssemblies?) Regards, Scot Kelly. ps: a little revolution now and then is a good thing python code: import sys sys.path.append('c:\Python25\Lib\site-packages\Clr') #Contains two files: clr.pyd and Python.Runtime.dll. import clr def CallMicrosoftStringClass(): #clr.AddReference("System") #from System import String as DotNetString #print clr.ListAssemblies() print 'Welcome to CallMicrosoftStringClass.' a = DotNetString('SomeTyping') print 'a is a instance of ' + a.__class__.__name__ print 'a', a b = DotNetString(a.PadRight(15, 'x')) print 'b', b c = DotNetString(b.Insert(2,'abc')) print 'c', c d = c.ToUpper() #note: not calling construtor of DotNetString here. print 'd', d print 'd is a instance of ' + d.__class__.__name__ print 'Leaving CallMicrosoftStringClass.' def CallObjectTwo(): #Import System clr.AddReference("CallbackExample") print '1111.a' print clr.FindAssembly("CallbackExample") print '1111.b' #print dir(clr) for e in clr.ListAssemblies(0): print e print '1111.c' for e in clr.ListAssemblies(1): print e print '1111.d' #from Namspacexyz import ObjectTwo as ObjDos #import CallbackExample import ObjectTwo print '2222' print 'Welcome to CallObjectTwo.' #a = ObjectDos('SomeTyping') #print 'a is a instance of ' + a.__class__.__name__ print 'Leaving CallObjectTwo.' print ' ' print ' ' print ' ' print ' ' print ' ' print ' ' print ' ' #for element in sys.path: # print element print 'Welcome to Scots_ClrExample '*3 CallObjectTwo() print 'Finished with Scots_ClrExample '*3 VB.net code: Imports System 'Imports System.Collections.ArrayList 'Imports System.Collections 'Imports System.Threading 'Imports System.Runtime.InteropServices 'Imports System.Data.Sql 'Imports System.Data.SqlTypes 'Imports Microsoft.SqlServer.Server ''Imports System.Win32Native 'How to compile: ' cd "c:\Program Files\Microsoft Sql Server" ' path=%path%;%SystemRoot%\Microsoft.NET\Framework\v2.0.50727 ' vbc /target:library "CallbackExample.vb" | more Public Namespace NSPC 'Public Module CallbackExample 'Demo callback functionality Public Class ObjectTwo Public Shared Function HelloWorld() as string return "Hello World from ObjectTwo !!" End Function Public Shared Function TestCallBack(obj As Object) As string Dim sResult as string sResult = "Hello" obj.CallbackFunc237(sResult) sResult = "Goodbye" return sResult 'new SqlChars(CSTR(sResult)) End Function End Class 'End Module End Namespace PASSPORT CAPITAL 30 Hotaling Place, Suite 300 San Francisco, CA 94111 www.passportcapital.com Scot Kelly Tel 415-525-8910 Fax 415-321-4620 skelly at passportcapital.com CONFIDENTIALITY: The information transmitted is intended only for the addressee and may contain confidential or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by anyone other than the intended recipient is prohibited. If you received this message in error, please contact the sender and delete the material from all computers. E-mail transmissions cannot be guaranteed to be secure or error-free and we accept no liability for any errors or omissions. We screen for viruses on a routine basis, however, we make no representation or warranty as to the absence of viruses in this e-mail or any attachments. Please note that for regulatory and compliance reasons we may monitor and read e-mails sent to and from our servers. Passport Capital, LLC and its affiliated investment vehicles are actively engaged in investment management and evaluation activities in global markets and do not wish to be exposed to any nonpublic information regarding any company(s) or security(s) that could be deemed material and restrict their ability to trade securities without their express prior consent. -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.d.lloyd at gmail.com Mon Jan 23 05:31:19 2012 From: brian.d.lloyd at gmail.com (Brian Lloyd) Date: Sun, 22 Jan 2012 23:31:19 -0500 Subject: [Python.NET] python for .net In-Reply-To: References: Message-ID: Hi Scot - generally CLR namespaces == python modules, so after loading the assembly I think you need to import NSPC. I don't have any VB experience, so not sure offhand what a VB Module corresponds to / compiles to in managed code (guessing it corresponds to a compilation unit at first glance, but its been a long while since I've worked on this stuff). Short story, whatever Imports statements you would use to use your code in an external VB file would need to have corresponding import statements in Python code... Hope this helps! - Brian On Fri, Jan 20, 2012 at 4:37 PM, Scot Kelly wrote: > ** > > ** ** > > Re: Python for .NET.**** > > ** ** > > All,**** > > I have created a Clr example which instantiates and manipulates objects of > type System.String.**** > > When I try to have it access the HelloWorld-esque object that I have > written in VB.net python throws an error on my import statement.**** > > In the docs on ?Python for .NET? there?s no discussion on what form the > .NET code must be in to be reachable, in terms of namespaces, modules and > classes.**** > > Here?s my code. I?ve tried encapsulating my class in Namespace and Module > wrappers no avail. Perhaps the lack of a PublicKeyToken is an ssue.**** > > Any help you can provide would be greatly appreciated.**** > > ** ** > > ** ** > > Feedback...**** > > I thought the process was fairly simple. **** > > 0. The inclusion of python.exe in the .zip merits annotating as optional.* > *** > > 1. The readme should probably discuss the need to > sys.path.append('c:\Python25\Lib\site-packages\Clr').**** > > 2. I thought the filename, Python.Runtime.dll, was too generic. Is it > within your abilities to name it more specifically, such as > PythonForNet.Runtime.dll**** > > 3. There?s no reference section for the methods of clr. (ex: what is the > parameter to and usage of ListAssemblies?)**** > > ** ** > > Regards,**** > > **Scot Kelly**.**** > > ** ** > > ps: a little revolution now and then is a good thing**** > > ** ** > > ** ** > > ** ** > > python code:**** > > import sys**** > > ** ** > > ** ** > > sys.path.append('c:\Python25\Lib\site-packages\Clr') #Contains two files: > clr.pyd and Python.Runtime.dll.**** > > import clr**** > > ** ** > > ** ** > > ** ** > > def CallMicrosoftStringClass():**** > > #clr.AddReference("System")**** > > #from System import String as DotNetString**** > > #print clr.ListAssemblies()**** > > ** ** > > print 'Welcome to CallMicrosoftStringClass.'**** > > a = DotNetString('SomeTyping')**** > > print 'a is a instance of ' + a.__class__.__name__**** > > print 'a', a**** > > b = DotNetString(a.PadRight(15, 'x'))**** > > print 'b', b**** > > c = DotNetString(b.Insert(2,'abc'))**** > > print 'c', c **** > > d = c.ToUpper() #note: not calling construtor of DotNetString here.*** > * > > print 'd', d**** > > print 'd is a instance of ' + d.__class__.__name__**** > > print 'Leaving CallMicrosoftStringClass.'**** > > ** ** > > ** ** > > ** ** > > def CallObjectTwo():**** > > #Import System **** > > clr.AddReference("CallbackExample")**** > > print '1111.a'**** > > print clr.FindAssembly("CallbackExample")**** > > print '1111.b'**** > > #print dir(clr)**** > > for e in clr.ListAssemblies(0):**** > > print e**** > > print '1111.c'**** > > for e in clr.ListAssemblies(1):**** > > print e**** > > print '1111.d'**** > > #from Namspacexyz import ObjectTwo as ObjDos**** > > #import CallbackExample**** > > import ObjectTwo **** > > print '2222'**** > > **** > > print 'Welcome to CallObjectTwo.'**** > > #a = ObjectDos('SomeTyping')**** > > #print 'a is a instance of ' + a.__class__.__name__**** > > print 'Leaving CallObjectTwo.'**** > > **** > > ** ** > > ** ** > > print ' '**** > > print ' '**** > > print ' '**** > > print ' '**** > > print ' '**** > > print ' '**** > > print ' '**** > > #for element in sys.path:**** > > # print element**** > > print 'Welcome to Scots_ClrExample '*3**** > > CallObjectTwo()**** > > print 'Finished with Scots_ClrExample '*3**** > > ** ** > > ** ** > > ** ** > > ** ** > > VB.net code:**** > > Imports System**** > > 'Imports System.Collections.ArrayList**** > > ** ** > > 'Imports System.Collections**** > > 'Imports System.Threading**** > > 'Imports System.Runtime.InteropServices**** > > 'Imports System.Data.Sql**** > > 'Imports System.Data.SqlTypes**** > > 'Imports Microsoft.SqlServer.Server**** > > ''Imports System.Win32Native**** > > ** ** > > 'How to compile:**** > > ' cd "c:\Program Files\Microsoft Sql Server"**** > > ' path=%path%;%SystemRoot%\Microsoft.NET\Framework\v2.0.50727**** > > ' vbc /target:library "CallbackExample.vb" | more**** > > ** ** > > ** ** > > Public Namespace NSPC**** > > ** ** > > 'Public Module CallbackExample**** > > ** ** > > 'Demo callback functionality**** > > Public Class ObjectTwo**** > > Public Shared Function HelloWorld() as string**** > > return "Hello World from ObjectTwo !!"**** > > End Function**** > > **** > > Public Shared Function TestCallBack(obj As Object) As string**** > > Dim sResult as string**** > > sResult = "Hello"**** > > obj.CallbackFunc237(sResult) **** > > sResult = "Goodbye"**** > > return sResult 'new SqlChars(CSTR(sResult)) **** > > End Function**** > > End Class**** > > ** ** > > 'End Module**** > > End Namespace**** > > ** ** > > ** ** > > * * > PASSPORT CAPITAL > 30 Hotaling Place, Suite 300 > San Francisco, CA 94111 > www.passportcapital.com > > *Scot Kelly > *Tel 415-525-8910 > Fax 415-321-4620 > skelly at passportcapital.com > > > > > CONFIDENTIALITY: The information transmitted is intended only for the > addressee and may contain confidential or privileged material. Any review, > retransmission, dissemination or other use of, or taking of any action in > reliance upon, this information by anyone other than the intended recipient > is prohibited. If you received this message in error, please contact the > sender and delete the material from all computers. > > E-mail transmissions cannot be guaranteed to be secure or error-free and > we accept no liability for any errors or omissions. We screen for viruses > on a routine basis, however, we make no representation or warranty as to > the absence of viruses in this e-mail or any attachments. Please note that > for regulatory and compliance reasons we may monitor and read e-mails sent > to and from our servers. > > Passport Capital, LLC and its affiliated investment vehicles are actively > engaged in investment management and evaluation activities in global > markets and do not wish to be exposed to any nonpublic information > regarding any company(s) or security(s) that could be deemed material and > restrict their ability to trade securities without their express prior > consent. > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > -- Brian Lloyd brian.d.lloyd at gmail.com (c) 540.845.2975 -------------- next part -------------- An HTML attachment was scrubbed... URL: From snaury at gmail.com Mon Jan 23 21:33:32 2012 From: snaury at gmail.com (Alexey Borzenkov) Date: Tue, 24 Jan 2012 00:33:32 +0400 Subject: [Python.NET] Several Python.Runtime problems Message-ID: Hello, While using Python.NET in one of my projects I found some problems: 1. PythonException uses Runtime.PyErr_Fetch before calling AcquireLock, which is wrong. Here's the patch: --- src/runtime/pythonexception.cs (revision 138) +++ src/runtime/pythonexception.cs (working copy) @@ -27,11 +27,11 @@ public PythonException() : base() { + IntPtr gs = PythonEngine.AcquireLock(); Runtime.PyErr_Fetch(ref _pyType, ref _pyValue, ref _pyTB); Runtime.Incref(_pyType); Runtime.Incref(_pyValue); Runtime.Incref(_pyTB); - IntPtr gs = PythonEngine.AcquireLock(); if ((_pyType != IntPtr.Zero) && (_pyValue != IntPtr.Zero)) { string type = new PyObject(_pyType).GetAttr("__name__").ToString(); 2. Every time .NET code throws an exception Python.NET leaks memory, because exception object is not decref'ed after calling PyErr_SetObject. In my case there were lots of exceptions, so problem was very noticable over time. Here's the patch: -- src/runtime/exceptions.cs (revision 138) +++ src/runtime/exceptions.cs (working copy) @@ -473,6 +473,7 @@ IntPtr etype = Runtime.PyObject_GetAttrString(op, "__class__"); Runtime.PyErr_SetObject(etype, op); Runtime.Decref(etype); + Runtime.Decref(op); } /// Hope this helps others in their fights for thread safety and against memory leaks. :) Thanks, Alexey. From snaury at gmail.com Mon Jan 23 21:42:50 2012 From: snaury at gmail.com (Alexey Borzenkov) Date: Tue, 24 Jan 2012 00:42:50 +0400 Subject: [Python.NET] [ pythonnet-Bugs-3303462 ] Stack corruption In-Reply-To: <4DD804D1.1090608@bcdesignswell.com> References: <4DD804D1.1090608@bcdesignswell.com> Message-ID: Btw, see my latest email, the PythonException patch will possibly fix this problem. On Sat, May 21, 2011 at 10:30 PM, Barton wrote: > Thank you very much! > It will be helpful for us to know which platform (Windows [Mono or .NET] vs > Linux) where this is happening. > > On 05/17/11 10:52, SourceForge.net wrote: >> >> Bugs item #3303462, was opened at 2011-05-18 02:52 >> Message generated for change (Tracker Item Submitted) made by christallire >> You can respond by visiting: >> >> https://sourceforge.net/tracker/?func=detail&atid=823891&aid=3303462&group_id=162464 >> >> Please note that this message will contain a full copy of the comment >> thread, >> including the initial issue submission, for this request, >> not just the latest update. >> Category: None >> Group: None >> Status: Open >> Resolution: None >> Priority: 5 >> Private: No >> Submitted By: xeph (christallire) >> Assigned to: Nobody/Anonymous (nobody) >> Summary: Stack corruption >> >> Initial Comment: >> I'm using python.net heavily in my server/client project >> >> I found Stack buffer overflow exception OR stack corruption exception is >> caused when python script throws an exception, which is caught by CLR code >> especially when GC is collecting its own objects. >> I think this problem is caused when allocated objects are unwinded by CLR >> engine. >> (threw in CLR GC Collection/GC Security Cookie Check) >> >> I found problem this 2 months ago, been struggling to solve this problem, >> because it happens rarely, randomly when GC is collecting objects >> I solved this problem via removing all of pythonexception throwing code >> from PythonEngine, changed to return parameters to null >> >> Hope you have better solution for solve this problem :) >> >> ---------------------------------------------------------------------- >> >> You can respond by visiting: >> >> https://sourceforge.net/tracker/?func=detail&atid=823891&aid=3303462&group_id=162464 >> > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet From barton at BCDesignsWell.com Thu Jan 26 09:11:14 2012 From: barton at BCDesignsWell.com (Barton) Date: Thu, 26 Jan 2012 00:11:14 -0800 Subject: [Python.NET] Several Python.Runtime problems In-Reply-To: References: Message-ID: <4F210AA2.9040507@BCDesignsWell.com> Thanks, Alexey, I've applied your patches to the trunk. It's great to have on the project! On 1/23/2012 12:33 PM, Alexey Borzenkov wrote: > Hello, > > While using Python.NET in one of my projects I found some problems: > > 1. PythonException uses Runtime.PyErr_Fetch before calling > AcquireLock, which is wrong. Here's the patch: > > --- src/runtime/pythonexception.cs (revision 138) > +++ src/runtime/pythonexception.cs (working copy) > @@ -27,11 +27,11 @@ > > public PythonException() : base() > { > + IntPtr gs = PythonEngine.AcquireLock(); > Runtime.PyErr_Fetch(ref _pyType, ref _pyValue, ref _pyTB); > Runtime.Incref(_pyType); > Runtime.Incref(_pyValue); > Runtime.Incref(_pyTB); > - IntPtr gs = PythonEngine.AcquireLock(); > if ((_pyType != IntPtr.Zero)&& (_pyValue != IntPtr.Zero)) > { > string type = new PyObject(_pyType).GetAttr("__name__").ToString(); > > 2. Every time .NET code throws an exception Python.NET leaks memory, > because exception object is not decref'ed after calling > PyErr_SetObject. In my case there were lots of exceptions, so problem > was very noticable over time. Here's the patch: > > -- src/runtime/exceptions.cs (revision 138) > +++ src/runtime/exceptions.cs (working copy) > @@ -473,6 +473,7 @@ > IntPtr etype = Runtime.PyObject_GetAttrString(op, "__class__"); > Runtime.PyErr_SetObject(etype, op); > Runtime.Decref(etype); > + Runtime.Decref(op); > } > > /// > > Hope this helps others in their fights for thread safety and against > memory leaks. :) > > Thanks, > Alexey. > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From guillaume.pichard at sogeti.com Tue Jan 31 16:39:42 2012 From: guillaume.pichard at sogeti.com (Guillaume Pichard) Date: Tue, 31 Jan 2012 16:39:42 +0100 Subject: [Python.NET] PyType_Ready "AccessViolationException was unhandled" Message-ID: <20120131163942.1yskp03ltwgks8k8@mail.sogeti.com> Hello, I have an exception: System.AccessViolationException was unhandled Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Source=Python.Runtime when using Converter.ToPythonImplicit with my own C# class as value. CustomClass value = new CustomClass(); Converter.ToPythonImplicit(value); I have the exception in typemanager.cs function CreateType when calling Runtime.PyType_Ready(type); What did I do wrong ? Thanks, Guillaume. From mathedotnet at gmail.com Tue Jan 31 18:46:46 2012 From: mathedotnet at gmail.com (MATHE MANOJ) Date: Tue, 31 Jan 2012 23:16:46 +0530 Subject: [Python.NET] PyType_Ready "AccessViolationException was unhandled" In-Reply-To: <20120131163942.1yskp03ltwgks8k8@mail.sogeti.com> References: <20120131163942.1yskp03ltwgks8k8@mail.sogeti.com> Message-ID: Hello Guillaume I think its because of base datatype casting inside that method. Manoj On Tue, Jan 31, 2012 at 9:09 PM, Guillaume Pichard < guillaume.pichard at sogeti.com> wrote: > Hello, > > I have an exception: > > System.**AccessViolationException was unhandled > Message=Attempted to read or write protected memory. This is often an > indication that other memory is corrupt. > Source=Python.Runtime > > when using Converter.ToPythonImplicit with my own C# class as value. > > CustomClass value = new CustomClass(); > Converter.ToPythonImplicit(**value); > > I have the exception in typemanager.cs function CreateType when calling > Runtime.PyType_Ready(type); > > What did I do wrong ? > > Thanks, > Guillaume. > > ______________________________**___________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/**mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: