[java-gnome-hackers] String changes
Brought to you by:
afcowie
From: Mark H. <mh...@ti...> - 2003-03-24 01:52:00
|
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... |