[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: JNIGenerator problem

Hi,

You're right, there isn't currently support for this.  The problem is that
for arguments with primitive types like int, it's not known if a value of 0
is an intended value or an unset one.  This is why the case with arguments
of type struct can be handled a bit better, because null can be equated with
unset.

If you have a proposal for an improvement to the JNIGenerator for cases like
this then you can log a report with swt and Silenio can consider it.

Grant


"L. Mihalkovic" <totolaricot@xxxxxxx> wrote in message
news:g14qam$92m$1@xxxxxxxxxxxxxxxxxxxx

Thank you for taking the time when you guys must be quite busy with
Ganymede.


I came to the same understanding.  The following is what triggered my
question:

-------------------------------------------------
/**********************************************************************
 * Copyright (c) 2003-2008 IBM Corp.
 * Portions Copyright (c) 1983-2002, Apple Computer, Inc.
 *
 * All rights reserved.  This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     L. Mihalkovic - initial version
 **********************************************************************/
package org.eclipse.swt.internal.carbon;

public class HIViewImageContentInfo {
    public short contentType;
    // the following is really a union
    public int data;
//    public short resID;
//    public int iconRef;
//    public int imageRef;
//    public int cIconHandle;
//    public int iconSuite;
//    public int picture;
//    public int ICONHandle;
    public static final int sizeof = 6;
}
-------------------------------------------------

in the SWT philosophy, I wanted to be able to write Java code that would use
the real Carbon field name based on the correct icon type. but the problem
is that the commented out code led to the mess you can imagine: the last
field being the current value of the underlying union - basically always 0
in my case (took me a couple days to figure that one out... not my proudest
moment).  So the current version has all the real union fields commented out
and uses a generic "data" field instead (to avoid the question of why 'does
that mean only icons of type XXXX are supported? '). Like I said, it
works... but I was wondering if there was a 'secret' syntax in JNIgenerator
to support real unions (basically generate an if statement in the JNI code).
Looking at the source I don't think so... (any plans for one?)



Grant Gayed wrote:
Hi Laurent,

Sorry, I meant to answer this when you asked it previously but forgot.

In most cases the best that can be done is to pick one of the union members
and always access the union through this chosen member, as you've seen.
However in this case it should be possible to do a bit better since the
union members are structs.  You can declare your
DataBrowserAccessibilityItemInfo.java to have fields for both v0 and v1,
both initially null.  Since DataBrowserAccessibilityItemInfo's "version"
field indicates which version of DataBrowserAccessibilityItemInfoV? is in
the union, you can just set the value of either the v0 or v1 field as
appropriate.  The generated memmove code should be smart enough to ignore
the other field that was not set.  The total size of
DataBrowserAccessibilityItemInfo will be 4 (for the version field) + sizeof
(DataBrowserAccessibilityItemInfoV1) .

HTH,
Grant


"L. Mihalkovic" <totolaricot@xxxxxxx> wrote in message
news:g0pgvk$bbr$1@xxxxxxxxxxxxxxxxxxxx
L. Mihalkovic wrote:
I am trying to map the Carbon HIViewImageContentInfo struct for SWT (yes, I
did figure how to declare a struct that contains a union by looking at other
examples): as far as I can tell by looking at the C generated the union
capability is actually lost (the ability to choose at runtime which field I
want to set).

I looked at pretty much all the other carbon structures that contain unions,
and in all cases, the SWT code has made a choice of using only one of the
members of the union via

for example:

struct DataBrowserAccessibilityItemInfo {

 /*
  * A UInt32 which identifies how to interpret the following union.
  * Set this field to zero if you fill out the union's data in the





  * field to one if you fill out the union's data in the form of a
  * DataBrowserAccessibilityItemInfoV1 structure.
  */
 UInt32              version;
 union {
   DataBrowserAccessibilityItemInfoV0  v0;
   DataBrowserAccessibilityItemInfoV1  v1;
 }                       u;
};

The mapping only provides access via v0 and access via the v1 definition is
lost. what if I want to be able to do

browserInfo.u.v1.xxxx = ssss

Am I missing something obvious?! (for now I did the same and mapped only one
of the fields knowing that the actual values would endup looking right to
Mac OS, but that does not strike me a legible code).




allo... anyone?

simply put can I do:


DataBrowserAccessibilityItemInfo XX;

XX.u.v0.aaaa = ....
AND
XX.u.v1.zzzz = ....


via some syntax in JNIGenerator. my impression so far is that I can do one
OR the other but not keep the real union behavior.






-- 
Laurent Mihalkovic, co-author SWT/JFace in Action (www.manning.com/scarpino)