| From | Sent On | Attachments |
|---|---|---|
| Harald Kuhr | Feb 9, 2010 11:58 am | |
| Duncan McGregor | Feb 9, 2010 12:04 pm | |
| Harald Kuhr | Feb 9, 2010 12:27 pm | |
| Harald Kuhr | Feb 9, 2010 12:37 pm | .java |
| Duncan McGregor | Feb 10, 2010 12:37 am | |
| Harald Kuhr | Feb 10, 2010 2:39 am | .java |
| Harald Kuhr | Feb 17, 2010 7:25 am | |
| Duncan McGregor | Feb 18, 2010 1:56 am | |
| Andrew Thompson | Feb 18, 2010 6:52 pm | |
| Harald Kuhr | Feb 19, 2010 6:49 am | |
| Harald Kuhr | Feb 19, 2010 7:23 am | |
| Harald Kuhr | Feb 19, 2010 10:37 am | |
| Harald Kuhr | Feb 19, 2010 12:13 pm | |
| Duncan McGregor | Feb 19, 2010 2:04 pm | |
| Harald Kuhr | Feb 19, 2010 3:06 pm | |
| Andrew Thompson | Feb 20, 2010 8:02 am | |
| Harald Kuhr | Feb 20, 2010 1:12 pm | |
| Andrew Thompson | Feb 20, 2010 5:22 pm | |
| Duncan McGregor | Feb 21, 2010 2:55 am | |
| Harald Kuhr | Feb 21, 2010 8:14 am | |
| Duncan McGregor | Feb 21, 2010 8:40 am | |
| Duncan McGregor | Feb 21, 2010 9:01 am |
| Subject: | Re: BOOL mapping issues | |
|---|---|---|
| From: | Harald Kuhr (hara...@gmail.com) | |
| Date: | Feb 21, 2010 8:14:26 am | |
| List: | net.java.dev.rococoa.users | |
On 21. feb. 2010, at 11.56, Duncan McGregor wrote:
On 21 Feb 2010, at 01:22, Andrew Thompson wrote:
On Feb 20, 2010, at 4:12 PM, Harald Kuhr wrote:
Jokes aside.. Do you know if it's always safe to use the mapping I proposed? At
least both bool and BOOL seems to use 1 rather than -1.
I have no explicit knowledge that this is safe, but logically what you did seems
harmless and makes sense.
I suppose ideally we should only apply the mapping where the param type is
actually BOOL and not just whenever the argument on the Java side is a boolean.
Aye, there's the rub. You see all we know about the param type (at the moment)
is that it is Java boolean.
That's what I figured as well, so I didn't try for anything more fancy.
This was the gist of my example passing it as Object - the mapping at the moment
is entirely JNA, and JNA assumes that the Java type maps to the correct native
type.
Now it seems to me that we have 3 options.
1 - Pick a mapping and stick to it. So Java boolean (actually Boolean by the
time we get to the invocation) always maps to int32 with 1 = YES, 0 = NO.
Strictly, BOOL and bool (stbool.h) are both typedef'ed as signed char, I guess
that is a java.lang.Byte in Java. But I figured it didn't make any difference,
as the only values ever used are 0 and 1 and JNA does the magic in any case.
2 - Look up the method signature for the selector that we are about to invoke,
and use that to inform our mapping. This is slow, but could be cached, and would
allow us to finesse our current silly issues with having to use CGFloat etc as
classes.
3 - Map boolean -> BOOL and provide an annotation to specify exceptions.
I'm actually quite keen on 2, but one is obviously simplest.
If we need to anything at all (your question below), I agree 2 is by far the
most elegant solution. 3 might be better if 2 can't be made to perform well
enough.
Does anyone have an example of a Mac API where JNA's default mapping actually
makes sense, because if not maybe we should suggest the change there?
Hmm.. I did a quick google for boolean types, and it seems that 1 is the most
common way to represent true (see for example
http://en.wikipedia.org/wiki/Boolean_data_type), even though I'm sure they
tought me -1 was the best representation at the university.. Given 1 is the
standard in all C variants, it is a little strange that JNA would choose -1.
Best regards,
-- Harald K






.java