Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] struct sizes hardcoded?

Quoting Tom Tromey <tromey@xxxxxxxxxx>:

> >>>>> "Seth" == Seth Nickell <snickell@xxxxxxxxxxxx> writes:
> 
> >> public static final int sizeof = OS.sizeof ("GdkColor");
> 
> Seth> I didn't think sizeof took a string? I don't know of a wayy in
> Seth> JNI to pass the actual type to a native function (not saying
> Seth> there's not one, only that I couldn't find it ;-), so unless
> JNI
> Seth> includes some sort of mechanism for getting "sizeof", native
> Seth> calls to every type you want to get the size of are necessary.
> 
> In my scheme you'd need a table mapping type names to sizes.  Your
> suggestion of having a separate native method for each type is
> pretty
> much the same idea.  It is just implemented a bit differently.  For
> my
> current purposes (estimating the amount of work involved), this
> detail
> seems unimportant.

Ah yes, I'm more inclined to go with a mechanism similar to yours. I was
thinking it would be good to have a single function that fills out a
whole table of these things. sizeofs aren't the only elements where this
would be useful, others are things like the exact values of G_TYPE_* and
things like that. While these are less critical since they aren't (to my
knowledge) likely to change in the near future it does seem prone to
error to duplicate all the numbering for the masks, type values, event
values, and other constants already present in the GTK headers. A simple
native function that fills in a "NativeConstant" class at startup would
be reasonably fast (copying ints is a one of the faster operations one
can perform :-) and would resolve my concerns raised by the hardcoding
of values in OS.java. Also it would allow convenient retrieval of GTypes
that *aren't* hardcoded but are commonly used in code (like the GType
for GObject).

-Seth


Back to the top