Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
2009/3/23 Curt Hagenlocher c...@hagenlocher.org: It's not quite that straightforward with p/Invoke though -- it can be *very* convenient to define multiple overloads for the same C function with different signatures. Consider the GetPrinter function and the different versions of the PRINTER_INFO_x structure it can deal with: http://msdn.microsoft.com/en-us/library/dd144911(VS.85).aspx My eyes! The goggles, they do nothing! Seo also mentioned printf-style varargs functions, which need a different signature for each set of arguments. Back to the drawing board. - Jeff ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
Do you actually need MakeOrAdd or would the factory that takes multiple method infos be good enough? I'm just reluctant to open up the ability to modify any built-in function. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users- boun...@lists.ironpython.com] On Behalf Of Jeff Hardy Sent: Saturday, March 21, 2009 1:17 PM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 Hi Dino, I'm updating Seo's old ctypes.py to work with 2.6, so unfortuantely it's a little more complex than just one method. I could probably use a delegate that takes an object[], but BuiltinFunction contains that code already, and it is a lot more optimized than I could manage. Plus it's less code for me to write :). - Jeff On Sat, Mar 21, 2009 at 11:45 AM, Dino Viehland di...@microsoft.com wrote: If you only have 1 method and don't need overload resolution I'd suggest making a delegate using System.Delegate.CreateDelegate. Otherwise this could be made public. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
I seem to recall that in Seo's original code, MakeOrAdd was used to build up the overloads over time as user code asked for additional method signatures for the same method name. This could presumably be simulated by replacing the method group in Python with a new method group that contained all the original infos plus the new one. On Mon, Mar 23, 2009 at 11:11 AM, Dino Viehland di...@microsoft.com wrote: Do you actually need MakeOrAdd or would the factory that takes multiple method infos be good enough? I'm just reluctant to open up the ability to modify any built-in function. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users- boun...@lists.ironpython.com] On Behalf Of Jeff Hardy Sent: Saturday, March 21, 2009 1:17 PM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 Hi Dino, I'm updating Seo's old ctypes.py to work with 2.6, so unfortuantely it's a little more complex than just one method. I could probably use a delegate that takes an object[], but BuiltinFunction contains that code already, and it is a lot more optimized than I could manage. Plus it's less code for me to write :). - Jeff On Sat, Mar 21, 2009 at 11:45 AM, Dino Viehland di...@microsoft.com wrote: If you only have 1 method and don't need overload resolution I'd suggest making a delegate using System.Delegate.CreateDelegate. Otherwise this could be made public. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
Maybe we could add a BuiltinFunctionBuild which provided this functionality. Then as long as the creator holds onto the BFB they can continue to mutate the function w/o allowing anyone else to. From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, March 23, 2009 3:43 PM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 I seem to recall that in Seo's original code, MakeOrAdd was used to build up the overloads over time as user code asked for additional method signatures for the same method name. This could presumably be simulated by replacing the method group in Python with a new method group that contained all the original infos plus the new one. On Mon, Mar 23, 2009 at 11:11 AM, Dino Viehland di...@microsoft.commailto:di...@microsoft.com wrote: Do you actually need MakeOrAdd or would the factory that takes multiple method infos be good enough? I'm just reluctant to open up the ability to modify any built-in function. -Original Message- From: users-boun...@lists.ironpython.commailto:users-boun...@lists.ironpython.com [mailto:users-mailto:users- boun...@lists.ironpython.commailto:boun...@lists.ironpython.com] On Behalf Of Jeff Hardy Sent: Saturday, March 21, 2009 1:17 PM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 Hi Dino, I'm updating Seo's old ctypes.py to work with 2.6, so unfortuantely it's a little more complex than just one method. I could probably use a delegate that takes an object[], but BuiltinFunction contains that code already, and it is a lot more optimized than I could manage. Plus it's less code for me to write :). - Jeff On Sat, Mar 21, 2009 at 11:45 AM, Dino Viehland di...@microsoft.commailto:di...@microsoft.com wrote: If you only have 1 method and don't need overload resolution I'd suggest making a delegate using System.Delegate.CreateDelegate. Otherwise this could be made public. ___ Users mailing list Users@lists.ironpython.commailto:Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.commailto:Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
I've been thinking about whether that functionality is really needed. C doesn't support function overloading, so presumably there would only ever by one signature per name? I'll have to see if CPython supports that. - Jeff 2009/3/23 Curt Hagenlocher c...@hagenlocher.org: I seem to recall that in Seo's original code, MakeOrAdd was used to build up the overloads over time as user code asked for additional method signatures for the same method name. This could presumably be simulated by replacing the method group in Python with a new method group that contained all the original infos plus the new one. On Mon, Mar 23, 2009 at 11:11 AM, Dino Viehland di...@microsoft.com wrote: Do you actually need MakeOrAdd or would the factory that takes multiple method infos be good enough? I'm just reluctant to open up the ability to modify any built-in function. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users- boun...@lists.ironpython.com] On Behalf Of Jeff Hardy Sent: Saturday, March 21, 2009 1:17 PM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 Hi Dino, I'm updating Seo's old ctypes.py to work with 2.6, so unfortuantely it's a little more complex than just one method. I could probably use a delegate that takes an object[], but BuiltinFunction contains that code already, and it is a lot more optimized than I could manage. Plus it's less code for me to write :). - Jeff On Sat, Mar 21, 2009 at 11:45 AM, Dino Viehland di...@microsoft.com wrote: If you only have 1 method and don't need overload resolution I'd suggest making a delegate using System.Delegate.CreateDelegate. Otherwise this could be made public. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
It's not quite that straightforward with p/Invoke though -- it can be *very* convenient to define multiple overloads for the same C function with different signatures. Consider the GetPrinter function and the different versions of the PRINTER_INFO_x structure it can deal with: http://msdn.microsoft.com/en-us/library/dd144911(VS.85).aspx http://msdn.microsoft.com/en-us/library/dd144911(VS.85).aspx On Mon, Mar 23, 2009 at 4:21 PM, Jeff Hardy jdha...@gmail.com wrote: I've been thinking about whether that functionality is really needed. C doesn't support function overloading, so presumably there would only ever by one signature per name? I'll have to see if CPython supports that. - Jeff 2009/3/23 Curt Hagenlocher c...@hagenlocher.org: I seem to recall that in Seo's original code, MakeOrAdd was used to build up the overloads over time as user code asked for additional method signatures for the same method name. This could presumably be simulated by replacing the method group in Python with a new method group that contained all the original infos plus the new one. On Mon, Mar 23, 2009 at 11:11 AM, Dino Viehland di...@microsoft.com wrote: Do you actually need MakeOrAdd or would the factory that takes multiple method infos be good enough? I'm just reluctant to open up the ability to modify any built-in function. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users- boun...@lists.ironpython.com] On Behalf Of Jeff Hardy Sent: Saturday, March 21, 2009 1:17 PM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 Hi Dino, I'm updating Seo's old ctypes.py to work with 2.6, so unfortuantely it's a little more complex than just one method. I could probably use a delegate that takes an object[], but BuiltinFunction contains that code already, and it is a lot more optimized than I could manage. Plus it's less code for me to write :). - Jeff On Sat, Mar 21, 2009 at 11:45 AM, Dino Viehland di...@microsoft.com wrote: If you only have 1 method and don't need overload resolution I'd suggest making a delegate using System.Delegate.CreateDelegate. Otherwise this could be made public. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
Thanks Curt, that worked. Now I have a new problem - I can get a MethodInfo, but I need to be able to convert it to something I can call. Seo's old code used BuiltinFunction.MakeOrAdd, but that is now internal. Can this be made public, or is there a better way to handle it? - Jeff 2009/3/20 Curt Hagenlocher c...@hagenlocher.org: I think this is something that broke well before the 2.0 release. To work around it in pyc.py, we added DefineDynamicAssembly to the PythonOps class in IronPython: import clr clr.AddReference('IronPython') from IronPython.Runtime.Operations import PythonOps assemblyBuilder = PythonOps.DefineDynamicAssembly(...) ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
In case it's interesting or useful, I've attached some p/Invoke stuff I was playing with before I got derailed by the DefineDynamicAssembly problem and then joined Microsoft :). On Sat, Mar 21, 2009 at 10:45 AM, Dino Viehland di...@microsoft.com wrote: If you only have 1 method and don't need overload resolution I'd suggest making a delegate using System.Delegate.CreateDelegate. Otherwise this could be made public. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users- boun...@lists.ironpython.com] On Behalf Of Jeff Hardy Sent: Saturday, March 21, 2009 9:44 AM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 Thanks Curt, that worked. Now I have a new problem - I can get a MethodInfo, but I need to be able to convert it to something I can call. Seo's old code used BuiltinFunction.MakeOrAdd, but that is now internal. Can this be made public, or is there a better way to handle it? - Jeff 2009/3/20 Curt Hagenlocher c...@hagenlocher.org: I think this is something that broke well before the 2.0 release. To work around it in pyc.py, we added DefineDynamicAssembly to the PythonOps class in IronPython: import clr clr.AddReference('IronPython') from IronPython.Runtime.Operations import PythonOps assemblyBuilder = PythonOps.DefineDynamicAssembly(...) ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com pinvoke.py Description: Binary data ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
Hi Dino, I'm updating Seo's old ctypes.py to work with 2.6, so unfortuantely it's a little more complex than just one method. I could probably use a delegate that takes an object[], but BuiltinFunction contains that code already, and it is a lot more optimized than I could manage. Plus it's less code for me to write :). - Jeff On Sat, Mar 21, 2009 at 11:45 AM, Dino Viehland di...@microsoft.com wrote: If you only have 1 method and don't need overload resolution I'd suggest making a delegate using System.Delegate.CreateDelegate. Otherwise this could be made public. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
I think this is something that broke well before the 2.0 release. To work around it in pyc.py, we added DefineDynamicAssembly to the PythonOps class in IronPython: import clr clr.AddReference('IronPython') from IronPython.Runtime.Operations import PythonOps assemblyBuilder = PythonOps.DefineDynamicAssembly(...) 2009/3/20 Jeff Hardy jdha...@gmail.com Hi all, I'm unable to create a Dynamic assembly from IronPython using AppDomain.DefineDynamicAssembly. The Python file attached results in the following error: Traceback (most recent call last): File pinvoke.py, line 5, in pinvoke.py File mscorlib, line unknown, in DefineDynamicAssembly File mscorlib, line unknown, in InternalDefineDynamicAssembly File mscorlib, line unknown, in nCreateDynamicAssembly File mscorlib, line unknown, in CheckGrantSetHelper SystemError: Object reference not set to an instance of an object. The equivalent C# program (also attached) works fine. I'm guessing there's something special about IronPython's AppDomain, but I'm not sure what it is. This is using revision 48140. Any ideas? - Jeff ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6
It's actually a CLR bug - we can't call this method from a dynamic method. We could probably add a workaround and force it to always be called via reflection. From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, March 20, 2009 5:29 PM To: Discussion of IronPython Subject: Re: [IronPython] Creating Dynamic Assemblies from IronPython 2.6 I think this is something that broke well before the 2.0 release. To work around it in pyc.py, we added DefineDynamicAssembly to the PythonOps class in IronPython: import clr clr.AddReference('IronPython') from IronPython.Runtime.Operations import PythonOps assemblyBuilder = PythonOps.DefineDynamicAssembly(...) 2009/3/20 Jeff Hardy jdha...@gmail.commailto:jdha...@gmail.com Hi all, I'm unable to create a Dynamic assembly from IronPython using AppDomain.DefineDynamicAssembly. The Python file attached results in the following error: Traceback (most recent call last): File pinvoke.py, line 5, in pinvoke.py File mscorlib, line unknown, in DefineDynamicAssembly File mscorlib, line unknown, in InternalDefineDynamicAssembly File mscorlib, line unknown, in nCreateDynamicAssembly File mscorlib, line unknown, in CheckGrantSetHelper SystemError: Object reference not set to an instance of an object. The equivalent C# program (also attached) works fine. I'm guessing there's something special about IronPython's AppDomain, but I'm not sure what it is. This is using revision 48140. Any ideas? - Jeff ___ Users mailing list Users@lists.ironpython.commailto:Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com