Need Feedback: Centralize (j)int <-> HANDLE conversions under Win32?

Mohan Embar gnustuff@thisiscool.com
Fri Nov 7 04:04:00 GMT 2003


Hi People,

For my next little project, I was thinking of
centralizing the conversion of GCJ file handles
(which are (j)ints) and Win32 handles, which are
of type HANDLE or SOCKET. At present, we
indiscriminately do old-style C typecasts
between HANDLE, SOCKET and jint in the Win32 code.

(HANDLE is a typedef for a pointer type under Win32.
SOCKET is an unsigned int.)

What I'd like to do is put something in win32.h
which looks something like this (I'm just typing
this on-the-fly so be indulgent - and also keep
in mind that I'm bad at names):

typedef jint LibJavaFD;

extern LibJavaFD
toLibJavaFD(HANDLE);

extern LibJavaFD
toLibJavaFD(SOCKET);

extern HANDLE
toWin32Handle(LibJavaFD);

extern SOCKET
toWin32Socket(LibJavaFD);

...and make all conversions go through these
functions.

This is somewhat tangential to this:

http://gcc.gnu.org/ml/java-patches/2003-q3/msg00783.html

...but not necessarily mutually exclusive. I'm
not sure whether the above discussion was continued in
the CLASSPATH list or not.

Not only does this centralized conversion under Win32
seem to make sense to me, but it would be a bit of
insurance for the day that Win64 comes along and the
jint <-> HANDLE typecasts break. If this issue isn't
resolved in a more elegant way, then in the Win64, we
could have the conversion functions use integers which
are indices into a lookup table of HANDLEs. Of course,
access to this table would have to be synchronized,
but it would be better than nothing.

Your thoughts?

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/





More information about the Java mailing list