[Mono-osx] NObjective and Inheritance

Martin Smith martin.smith.jr at gmail.com
Tue Feb 10 14:28:51 EST 2009


Hello,

Do you have a mode that will not use the proxy-weaver based inheritance?
I'm debating adding one.  I realize it will make the generated proxies
pretty large, but I'm wondering how much larger it would make the compiled
binaries.  If  I had to guess, I'd think maybe 2x or 3x larger, which might
be a small price to pay to not have to rely on (as rodrigo mention) a Mono
CLR bug.

Rodrigo:
Are you saying that regardless of which method Eugeny uses, it will produce
largely the same IL?  The idea here is that there NSWindow is a struct that
takes 70% of it's methods from NSControl (and its base classes). In fact, a
method from NSObject or NSResponder (which sit at the bottom of the
Objective-C inheritance chains) would get duplicated across the entire
inheritance heirarchy (potentially hundreds or a few thousand times).  I'm
not 100% sure here.  Are you saying regardless of which solution is used,
the generated dlls should be roughly the same size?

I just want to make sure that I'm understanding everything.

Thanks!
Martin

On Mon, Feb 9, 2009 at 6:39 AM, Eugeny Grishul <eugeny.grishul at gmail.com>wrote:

>
> Hi,
> Thanks for deep code review =)
>
> Weaver pros and cons:
> 1) without inheritance proxy assemblies will be about 60M due to duplicated
> methods
> 2) it will be used for Objective-C property accessors for same goal
>
> Cons:
> 1) code produced by weaver is not verifiable. By spec CLI itself does not
> allow for value type inheritance:
>
> 8.9.7.
> ...
> 3. A value type does not inherit; rather the base type specified in the
> class definition defines the
> base type of the boxed type.
> 4. The base type of a boxed type shall not have any fields.
>
> 8.9.10.
> In their unboxed form value types do not inherit from any type. Boxed value
> types shall inherit directly from
> System.ValueType unless they are enumerations, in which case, they shall
> inherit from System.Enum. Boxed
> value types shall be sealed.
>
> My approach is a violation of the spec. If you run "peverify" on the
> assembly with one value type inheriting from another, it will tell you as
> much =) If mono won't support value-type inheritace in future it will be
> bug
> in ther JIT coz CLR implementation actually ALLOWS it.
> 2) Current Mono VES implementation have a bug related ot value type
> inheritance and to workaround it don't allow objc proxies to be boxed.
> Following code will crash JIT:
>
> public void ButtonPressed( NSButton sender )
> {
>    Console.WriteLine( "Pressed {0}", sender );
> ...
> ...
>
> And workaround:
> public void ButtonPressed( NSButton sender )
> {
>    Console.WriteLine( "Pressed {0}", sender.ToString() );
> ...
> ...
>
> About NObjectiveAST - it works like NRefactory and able to parse and save
> AST tree to file. But if you want to extend interoping abilities of
> resulting code then you should modify HeaderAnalyzer (
>
> http://code.google.com/p/nobjective/source/browse/trunk/ProxyGenerator/HeaderAnalyzer.cs
> ) which is not part of NObjectiveAST. The goal of mine bridge is
> Objective-C
> interop so I'll not plan to add support for automatical P/Invoke
> generation.. My friend's dimpoma thesis is related with automatical
> P/Invoke
> generation (he will use NObjectiveAST and test his work on creating Qt
> bindings with full code coverage) and may be after 5 months of his work we
> will see brialliant project..or not =) Anyway you can make patch and help
> to
> improve project =)
>
> WBR,
> Eugeny Grishul
>
>
> Martin Smith-8 wrote:
> >
> > Hello,
> >
> > I was looking at the NObjective source code, and noticed that that
> > basically
> > all the proxies are generated as structs.  The compiled assembly then
> gets
> > passed to a code weaver which fills in the Objective-C class inheritance
> > structure. The code weaver basically uses Mono.Cecil to make structs
> > support
> > inheritance.
> >
> > I guess this works, but the thing I'm wondering is: is it safe te rely on
> > the fact that the mono runtime can actually support inheritance for value
> > types?  Is this something that's supposed to be supported by the CLI but
> > just isnt supported by C#?  I'm assuming that there would be some serious
> > issues if all the proxies weren't the same size (i.e. with only an IntPtr
> > as
> > the instance data).
> >
> > At any rate, cheers Eugeny.  You've created a pretty impressive layer
> > here.
> > Have you thought about extending NObjectiveAST to suport interoping some
> > of
> > the C-based functions (for example, NSMakeRect, or the CGContext*
> > methods).
> >
> > Thanks again Eugeny for such great code!
> > Martin
> >
> > _______________________________________________
> > Mono-osx mailing list
> > Mono-osx at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-osx
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/NObjective-and-Inheritance-tp21882576p21914042.html
> Sent from the Mono - OSX mailing list archive at Nabble.com.
>
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20090210/456e263f/attachment.html 


More information about the Mono-osx mailing list