Author: mladen.turk(a)jboss.com
Date: 2007-10-15 06:57:40 -0400 (Mon, 15 Oct 2007)
New Revision: 1113
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/os/linux/console.c
trunk/sight/native/os/linux/scm.c
trunk/sight/native/os/solaris/console.c
trunk/sight/native/os/solaris/process.c
trunk/sight/native/os/solaris/scm.c
trunk/sight/native/os/windows/console.c
trunk/sight/native/os/windows/registry.c
trunk/sight/native/os/windows/scm.c
trunk/sight/native/share/jnu.c
Log:
Use macros for NewString JNI calls
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/include/sight_local.h 2007-10-15 10:57:40 UTC (rev 1113)
@@ -83,8 +83,11 @@
#define POOL_CLEAR 2
-#define CSTR_TO_JSTRING(V) (*_E)->NewStringUTF((_E), (V))
+#define CSTR_TO_JSTRING(V) (*_E)->NewStringUTF(_E, (char *)(V))
+#define WSTR_TO_JSTRING(V) (*_E)->NewString(_E, (jchar *)(V),
(jsize)wcslen((jchar *)(V)))
+#define ZSTR_TO_JSTRING(V, L) (*_E)->NewString(_E, (jchar *)(V), (L))
+
#define RETURN_JCSTR(V) \
if ((V)) return (*_E)->NewStringUTF((_E), (V)); \
else return NULL
Modified: trunk/sight/native/os/linux/console.c
===================================================================
--- trunk/sight/native/os/linux/console.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/linux/console.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -337,7 +337,7 @@
SIGHT_EXPORT_DECLARE(jstring, Console, gtitle0)(SIGHT_STDARGS)
{
UNREFERENCED_O;
- return (*_E)->NewStringUTF(_E, "Unknown");
+ return CSTR_TO_JSTRING("Unknown");
}
SIGHT_EXPORT_DECLARE(void, Console, kill3)(SIGHT_STDARGS)
Modified: trunk/sight/native/os/linux/scm.c
===================================================================
--- trunk/sight/native/os/linux/scm.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/linux/scm.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -201,7 +201,7 @@
return NULL;
}
for (i = 0; i < cnt; i++) {
- jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ jstring s = CSTR_TO_JSTRING(si->services->arr[i]);
if (s)
(*_E)->SetObjectArrayElement(_E, ea, idx++, s);
else
Modified: trunk/sight/native/os/solaris/console.c
===================================================================
--- trunk/sight/native/os/solaris/console.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/solaris/console.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -337,7 +337,7 @@
SIGHT_EXPORT_DECLARE(jstring, Console, gtitle0)(SIGHT_STDARGS)
{
UNREFERENCED_O;
- return (*_E)->NewStringUTF(_E, "Unknown");
+ return CSTR_TO_JSTRING("Unknown");
}
SIGHT_EXPORT_DECLARE(void, Console, kill3)(SIGHT_STDARGS)
Modified: trunk/sight/native/os/solaris/process.c
===================================================================
--- trunk/sight/native/os/solaris/process.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/solaris/process.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -362,7 +362,7 @@
jstring s;
if (lseek(fd, sa[n], SEEK_SET) != -1) {
if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = (*_E)->NewStringUTF((_E), pname);
+ s = CSTR_TO_JSTRING(pname);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -370,7 +370,7 @@
continue;
}
}
- s = (*_E)->NewStringUTF((_E), "");
+ s = CSTR_TO_JSTRING("");
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -412,7 +412,7 @@
jstring s;
if (lseek(fd, sa[n], SEEK_SET) != -1) {
if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = (*_E)->NewStringUTF((_E), pname);
+ s = CSTR_TO_JSTRING(pname);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -420,7 +420,7 @@
continue;
}
}
- s = (*_E)->NewStringUTF((_E), "");
+ s = CSTR_TO_JSTRING("");
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -455,7 +455,7 @@
memcpy(pr_name, &psinfo.pr_psargs[l], j-l);
j++;
l = j;
- s = (*_E)->NewStringUTF((_E), pr_name);
+ s = CSTR_TO_JSTRING(pr_name);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, k, s);
(*_E)->DeleteLocalRef(_E, s);
Modified: trunk/sight/native/os/solaris/scm.c
===================================================================
--- trunk/sight/native/os/solaris/scm.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/solaris/scm.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -199,7 +199,7 @@
return NULL;
}
for (i = 0; i < cnt; i++) {
- jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ jstring s = CSTR_TO_JSTRING(si->services->arr[i]);
if (s)
(*_E)->SetObjectArrayElement(_E, ea, idx++, s);
else
Modified: trunk/sight/native/os/windows/console.c
===================================================================
--- trunk/sight/native/os/windows/console.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/windows/console.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -226,7 +226,7 @@
UNREFERENCED_O;
if ((dwLen = GetConsoleTitleW(szBuf, SIGHT_HBUFFER_SIZ)) != 0) {
- return (*_E)->NewString(_E, (jchar *)&szBuf[0], dwLen);
+ return ZSTR_TO_JSTRING(&szBuf[0], dwLen);
}
else
return NULL;
@@ -269,10 +269,10 @@
/* set length of string and null terminate it */
if (wBuf[wLen] == L'\r') {
- rv = (*_E)->NewString(_E, wBuf, wLen - 2);
+ rv = ZSTR_TO_JSTRING(wBuf, wLen - 2);
}
else if ((wLen == MAX_CONSOLE_SIZE) && (wBuf[wLen - 1] == L'\r')) {
- rv = (*_E)->NewString(_E, wBuf, wLen - 1);
+ rv = ZSTR_TO_JSTRING(wBuf, wLen - 1);
}
else {
if (wLen > 0 && wBuf[wLen - 1] == L'\n')
@@ -280,9 +280,9 @@
if (wLen > 0 && wBuf[wLen - 1] == L'\r')
--wLen;
if (wLen)
- rv = (*_E)->NewString(_E, wBuf, wLen);
+ rv = ZSTR_TO_JSTRING(wBuf, wLen);
else
- rv = (*_E)->NewStringUTF(_E, "");
+ rv = CSTR_TO_JSTRING(_E, "");
}
cleanup:
Modified: trunk/sight/native/os/windows/registry.c
===================================================================
--- trunk/sight/native/os/windows/registry.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/windows/registry.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -450,7 +450,7 @@
free(vw);
goto cleanup;
}
- v = (*_E)->NewString(_E, vw, (jsize)wcslen(vw));
+ v = WSTR_TO_JSTRING(vw);
free(vw);
}
cleanup:
@@ -564,7 +564,7 @@
jchar *b = p;
while (*p)
p++;
- s = (*_E)->NewString(_E, b, (jsize)(p - b));
+ s = ZSTR_TO_JSTRING(b, (p - b));
if (s)
(*_E)->SetObjectArrayElement(_E, v, idx++, s);
else
@@ -824,7 +824,7 @@
NULL,
&ftLastWriteTime);
if (rc == (DWORD)ERROR_SUCCESS) {
- s = (*_E)->NewString(_E, achKey, (jsize)wcslen(achKey));
+ s = WSTR_TO_JSTRING(achKey);
if (s) {
(*_E)->SetObjectArrayElement(_E, v, idx, s);
if ((*_E)->ExceptionCheck(_E))
@@ -902,7 +902,7 @@
NULL, // &bData,
NULL); // &bcData
if (rc == (DWORD)ERROR_SUCCESS) {
- s = (*_E)->NewString(_E, achValue, (jsize)wcslen(achValue));
+ s = WSTR_TO_JSTRING(achValue);
if (s) {
(*_E)->SetObjectArrayElement(_E, v, idx, s);
if ((*_E)->ExceptionCheck(_E))
Modified: trunk/sight/native/os/windows/scm.c
===================================================================
--- trunk/sight/native/os/windows/scm.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/windows/scm.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -189,7 +189,7 @@
DWORD i;
lpService = (LPENUM_SERVICE_STATUS_PROCESSA)&head->data[0];
for (i = 0; i < head->size; i++) {
- jstring s = (*_E)->NewStringUTF(_E, lpService[i].lpServiceName);
+ jstring s = WSTR_TO_JSTRING(lpService[i].lpServiceName);
if (s)
(*_E)->SetObjectArrayElement(_E, ea, idx++, s);
else
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/share/jnu.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -289,7 +289,7 @@
n = 0;
for (p = str; p && *p; p++) {
- jstring s = (*_E)->NewStringUTF((_E), p);
+ jstring s = CSTR_TO_JSTRING(p);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -321,7 +321,7 @@
while (*p)
p++;
len = (jsize)(p - ptr);
- s = (*_E)->NewString((_E), ptr, len);
+ s = ZSTR_TO_JSTRING(ptr, len);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -342,7 +342,7 @@
return NULL;
for (i = 0; i < n; i++) {
- jstring s = (*_E)->NewStringUTF((_E), str[i]);
+ jstring s = CSTR_TO_JSTRING(str[i]);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, i, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -362,8 +362,7 @@
return NULL;
for (i = 0; i < n; i++) {
- jstring s = (*_E)->NewString((_E), str[i],
- sight_wcslen(str[i]));
+ jstring s = WSTR_TO_JSTRING(str[i]);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, i, s);
(*_E)->DeleteLocalRef(_E, s);