From: Markus H. <ma...@ti...> - 2009-10-31 16:01:28
|
Hi, what about this patch: @@ -183,11 +183,35 @@ int main(int argc, char* argv[]) <xsl:text> @implementation </xsl:text> <xsl:value-of select="vm:fixname(@package)"/> <xsl:text>_</xsl:text> <xsl:value-of select="vm:fixname(@name)"/> - + + + <!-- Emit constructor --> + <xsl:text> +-(id)init +{ + if (self = [super init]) + { +</xsl:text> + <!-- Emit declarations for all non-static object fields --> + <xsl:for-each select="vm:field[not(@isStatic = 'true') and vm:isObjectRef(@type)]"> + <xsl:text> </xsl:text> + <xsl:value-of select="vm:fixname(../@package)"/> + <xsl:text>_</xsl:text> + <xsl:value-of select="vm:fixname(../@name)"/> + <xsl:text>_</xsl:text> + <xsl:value-of select="vm:fixname(@name)"/> + <xsl:text>=[NSNull null]; +</xsl:text> + </xsl:for-each> +<xsl:text> } + return self; +} +</xsl:text> + <!-- Emit destructor --> <xsl:text>; - (void) dealloc; { This creates a constructor in the ObjC-class and fills all instance variables of any Object-type with [NSNull null]. This seems to work in my tests, but I don't know if it might break anything. Markus Am 30.10.2009 um 20:18 schrieb Arno Puder: > > this is a tricky issue. Objective-C initializes member variables to > 'nil' by default (which, I believe, is represented by 0x0). However, > in > XMLVM we cannot map Java's null to Objective-C's nil, because nil is > not > accepted as an argument to some data structures (e.g., NSArray, > NSDictionary, etc). That is why we map null to [NSNull null]. > > Now, very unfortunate, you cannot do something like this in > Objective-C: > > @interface Foo { > id ref = [NSNull null]; > } > @end > > This means, you have do some fancy code generation. This is a known > issue in XMLVM. In the meantime, you can explicitly initialize Java > members such as: > > public class Test { > Object ref = null; > ... > > Arno > > > Panayotis Katsaloulis wrote: >> On 30 Οκτ 2009, at 8:35 μ.μ., Markus Heberling wrote: >> >>> Hi, >>> >>> take this code convert it to objc and run it: >>> >>> public class Test{ >>> Object thisIsNotInitialized; >>> >>> void test(){ >>> if(thisIsNotInitialized==null) >>> System.out.println("null"); >>> } >>> >>> public static void main(String[] args){ >>> new Test().test(); >>> } >>> } >>> >>> I would expect to get "null" printed to the console. But that >>> doesn't happen. The generated if is something like thos: >>> >>> if (_op1.o != [NSNull null]) goto label0; >>> >>> So it checks for [NSNull null]. But _op1.o contains 0x0 and the >>> check is false. So I would guess that the initialization code of the >>> ObjC variables has to be changed so that they contain [NSNull null] >>> and not 0x0 by default. >>> >>> Hope you get what I mean. >> >> >> >> If a selector returns nil, what is seen in Java? >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart >> your >> developing skills, take BlackBerry mobile applications to market >> and stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ >> xmlvm-users mailing list >> xml...@li... >> https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart > your > developing skills, take BlackBerry mobile applications to market and > stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |