RE: [java-gnome-hackers] String changes
Brought to you by:
afcowie
From: Jeffrey M. <Jef...@Br...> - 2003-03-20 12:43:10
|
My only concern is that this is a very significant change. It will not be as simple as just regenerating the generated code since I have made changes and optimizations to many of the generated classes. Still, I think this is the right thing to do. Perhaps we should divide this activity up between several people to expedite the process. -Jeff -----Original Message----- From: Mark Howard [mailto:mh...@ti...] Sent: Wednesday, March 19, 2003 4:22 PM To: jav...@li... Subject: [java-gnome-hackers] String changes Hi, As discussed at the start of the year, I'd like to make some big changes to the way we handle passing of strings. The current code has major issues on some (non-Sun) Java environments (when working with zero length strings) and also does not take into account charset encoding. These changes: * use (*env)->GetStringUTFChars rather than jint str_len = (*env)->GetArrayLength(env, str); gchar* str_g = (gchar*)g_malloc(str_len + 1); (*env)->GetByteArrayRegion(env, str, 0, str_len, (jbyte*)str_g); str_g[str_len] = 0; * Also call (*env)->ReleaseStringUTFChars(env, str, str_g); - As far as I can see, the old code is wrong in that it should have been calling ReleaseByteArrayElements when done - please let me know if you don't agree with this. The attached files demonstrate the changes I propose. Test.c shows both the current and proposed methods They can be executed using gcc -c -g -O2 -fPIC Test.c -o Test.o -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include gcc -g -O2 -fPIC -shared -o libTest.so Test.o -Wl,--export-dynamic -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -Xlinker --no-undefined javac TestClass.java LD_LIBRARY_PATH=. java TestClass In my tests, the new code always also has improved performance (Java 1.4.1) The changes would require regenerating all the generated code and (hopefully semi-automatically) changing all calls to these. Any comments? -- .''`. Mark Howard : :' : `. `' http://www.tildemh.com `- mh...@de... | mh...@ti... | mh...@ca... |