Author: mturk
Date: Mon Mar 28 07:37:39 2011
New Revision: 1086143
URL: http://svn.apache.org/viewvc?rev=1086143&view=rev
Log:
Add direct FileDescriptor access. May not work on all VM's
Added:
commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h (with
props)
commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h
commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
commons/sandbox/runtime/trunk/src/main/native/shared/object.c
commons/sandbox/runtime/trunk/src/main/native/shared/observer.c
commons/sandbox/runtime/trunk/src/main/native/shared/string.c
commons/sandbox/runtime/trunk/src/main/native/shared/system.c
commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Mon Mar 28
07:37:39 2011
@@ -92,6 +92,7 @@ LIBSOURCES=\
$(TOPDIR)/shared/clazz.c \
$(TOPDIR)/shared/debug.c \
$(TOPDIR)/shared/error.c \
+ $(TOPDIR)/shared/iofd.c \
$(TOPDIR)/shared/memory.c \
$(TOPDIR)/shared/native.c \
$(TOPDIR)/shared/object.c \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Mon Mar
28 07:37:39 2011
@@ -1614,21 +1614,18 @@ extern "C" {
void
AcrReleaseExceptionClasses(JNI_STDENV);
-
void
AcrFatalError(JNI_STDENV,
const char *filename, const char *funcname, int lineno,
int error, const char *msg, ...);
-
+void
+AcrThrowByName(JNI_STDENV, const char *cls, const char *msg);
void
AcrThrow(JNI_STDENV, int cls, const char *msg);
-
void
AcrThrowClass(JNI_STDENV, const char *clazz, const char *msg);
-
void
AcrThrowException(JNI_STDENV, int clazz, int error);
-
void
AcrDebugThrowException(JNI_STDENV, const char *filename, const char *funcname,
int lineno, int clazz, int error);
Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h?rev=1086143&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h Mon Mar 28
07:37:39 2011
@@ -0,0 +1,48 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_IOFD_H
+#define _ACR_IOFD_H
+
+#include "acr/jniapi.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file iofd.h
+ * @brief
+ *
+ * ACR java.io.FileDescriptor support.
+ *
+ */
+
+ACR_CLASS_CTOR(FileDescriptor);
+ACR_CLASS_DTOR(FileDescriptor);
+
+int
+AcrFileDescriptorGetFd(JNI_STDARGS);
+#if defined (WINDOWS)
+HANDLE
+AcrFileDescriptorGetHandle(JNI_STDARGS);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_IOFD_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h Mon Mar
28 07:37:39 2011
@@ -64,6 +64,8 @@
#define V2I(P) ((int)(acr_intptr_t)(P))
#define V2U(P) ((unsigned int)(acr_uintptr_t)(P))
#define V2Z(X) ((X) ? JNI_TRUE : JNI_FALSE)
+#define INVALID_FIELD_OFFSET (-1)
+#define INVALID_FIELD_BASE (-1)
#define ACR_CLASS_CTOR(CL) \
int acr_class_##CL##_load(JNI_STDENV)
@@ -89,18 +91,8 @@
#define J_DECLARE_F_ID(I) static JAVA_F_ID _f##I##n
#define J_DECLARE_M_ID(I) static JAVA_M_ID _m##I##n
#define J4MID(I) _m##I##n.i
+#define J4FLD_OFF(I) _f##I##n.o
#define CLAZZ_LOADED (_clazzn.u != 0)
-#define UTF8_TO_JSTRING(V) AcrNewJavaStringU(_E, (const char *)(V))
-#define CSTR_TO_JSTRING(V) AcrNewJavaStringA(_E, (const char *)(V))
-#define WSTR_TO_JSTRING(V) AcrNewJavaStringW(_E, (const wchar_t *)(V))
-#if defined(_WINDOWS)
-#define PSTR_TO_JSTRING(V) AcrNewJavaStringW(_E, (const wchar_t *)(V))
-#define _PTEXT(X) L ## X
-#else
-#define PSTR_TO_JSTRING(V) AcrNewJavaStringU(_E, (const char *)(V))
-#define _PTEXT(X) X
-#endif
-
#endif /* _ACR_JNIDEFS_H_ */
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h Mon Mar
28 07:37:39 2011
@@ -282,6 +282,10 @@
#define ACR_OS_HPUX 0x20800
#define ACR_OS_AIX 0x21000
+#define ACR_TEST_MACRO(M) if ((M)) {
+#define ACR_BEGIN_MACRO if (1) {
+#define ACR_END_MACRO } else (void)(0)
+
#define UNUSED_SOURCE_FILE(F) \
const char __provided_##F [] = "Using system provided " #F "()"
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h Mon Mar
28 07:37:39 2011
@@ -19,9 +19,45 @@
#include "acr/jnitypes.h"
-#define ACR_CP_DEFAULT 0
-#define ACR_CP_ISO8859_1 1
-#define ACR_CP_UTF_8 2
+#define ACR_CP_DEFAULT 0
+#define ACR_CP_ISO8859_1 1
+#define ACR_CP_UTF_8 2
+
+#define UTF8_TO_JSTRING(V) AcrNewJavaStringU(_E, (const char *)(V))
+#define CSTR_TO_JSTRING(V) AcrNewJavaStringA(_E, (const char *)(V))
+#define WSTR_TO_JSTRING(V) AcrNewJavaStringW(_E, (const wchar_t *)(V))
+#if defined(_WINDOWS)
+#define PSTR_TO_JSTRING(V) AcrNewJavaStringW(_E, (const wchar_t *)(V))
+#define _PTEXT(X) L ## X
+#else
+#define PSTR_TO_JSTRING(V) AcrNewJavaStringU(_E, (const char *)(V))
+#define _PTEXT(X) X
+#endif
+#define J2S(V) _s##V
+
+#define WITH_WSTR(V) \
+ if (1) { \
+ wchar_t _b##V[ACR_MBUFF_SIZ]; \
+ wchar_t *_s##V = AcrGetJavaStringW(_E, (V), _b##V); \
+ if (_s##V == 0) goto _j##V;
+
+#define WITH_CSTR(V) \
+ if (1) { \
+ char _b##V[ACR_PBUFF_SIZ]; \
+ char *_s##V = AcrGetJavaStringA(_E, (V), _b##V); \
+ if (_s##V == 0) goto _j##V;
+
+#define WITH_USTR(V) \
+ if (1) { \
+ char _b##V[ACR_PBUFF_SIZ]; \
+ char *_s##V = AcrGetJavaStringU(_E, (V), _b##V); \
+ if (_s##V == 0) goto _j##V;
+
+#define DONE_WITH_STR(V) \
+ _j##V : \
+ if (_s##V != 0 && _s##V != _b##V) AcrFree(_s##V); \
+ } else (void)(0)
+
#ifdef __cplusplus
extern "C" {
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h Mon Mar
28 07:37:39 2011
@@ -20,8 +20,6 @@
#include "acr/jnitypes.h"
#include "acr/error.h"
-#define INVALID_FIELD_OFFSET (-1)
-
/**
* @file unsafe.h
* @brief
@@ -30,6 +28,11 @@
*
*/
+#define UNSAFE_OFF_IFIELD(I) \
+ if (_f##I##n.i != 0) { \
+ _f##I##n.o = AcrUnsafeObjectFieldIdOffset(_E, _clazzn.i, _f##I##n.i); \
+ } else (void)(0)
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -39,6 +42,16 @@ ACR_CLASS_DTOR(Unsafe);
jobject
AcrUnsafeGetInstance(JNI_STDENV);
+jint
+AcrUnsafeObjectFieldOffset(JNI_STDARGS);
+jint
+AcrUnsafeStaticFieldBase(JNI_STDARGS);
+jint
+AcrUnsafeStaticFieldOffset(JNI_STDARGS);
+jint
+AcrUnsafeObjectFieldIdOffset(JNI_STDENV, jclass cls, jfieldID fid);
+jint
+AcrUnsafeStaticFieldIdOffset(JNI_STDENV, jclass cls, jfieldID fid);
#ifdef __cplusplus
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/callback.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/callback.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/callback.c Mon Mar 28
07:37:39 2011
@@ -24,7 +24,7 @@
#include "acr/memory.h"
J_DECLARE_CLAZZ = {
- 0,
+ INVALID_FIELD_OFFSET,
0,
0,
0,
@@ -45,6 +45,7 @@ ACR_CLASS_CTOR(Callback)
return rv;
J_LOAD_METHOD(0000);
+ _clazzn.u = 1;
return 0;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Mon Mar 28
07:37:39 2011
@@ -23,9 +23,10 @@
#include "acr/system.h"
#include "acr/callback.h"
#include "acr/observer.h"
+#include "acr/iofd.h"
J_DECLARE_CLAZZ = {
- 0,
+ INVALID_FIELD_BASE,
0,
0,
0,
@@ -217,8 +218,9 @@ AcrInitCoreClasses(JNI_STDENV)
int
AcrLoadRuntimeClasses(JNI_STDENV)
{
- ACR_CLASS_LOPT(Unsafe);
ACR_CLASS_LOAD(Callback);
+ ACR_CLASS_LOPT(Unsafe);
+ ACR_CLASS_LOPT(FileDescriptor);
#ifdef WIN32
@@ -230,11 +232,12 @@ void
AcrUnloadRuntimeClasses(JNI_STDENV)
{
+ ACR_CLASS_UNLOAD(FileDescriptor);
ACR_CLASS_UNLOAD(Callback);
- ACR_CLASS_UNLOAD(Observer);
ACR_CLASS_UNLOAD(Unsafe);
- ACR_CLASS_UNLOAD(String);
+ ACR_CLASS_UNLOAD(Observer);
ACR_CLASS_UNLOAD(System);
+ ACR_CLASS_UNLOAD(String);
ACR_CLASS_UNLOAD(Object);
ACR_CLASS_UNLOAD(Class);
#ifdef WIN32
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Mon Mar 28
07:37:39 2011
@@ -21,6 +21,11 @@
#include "acr/port.h"
#include "acr/misc.h"
+/* TODO: Make that configurable if it
+ * start creating problems
+ */
+#define CACHE_THROWABLES 1
+
static struct {
jclass clazz;
const char *name;
@@ -582,16 +587,53 @@ AcrThrowClass(JNI_STDENV, const char *cl
return;
}
(*_E)->ThrowNew(_E, ec, msg);
- (*_E)->DeleteLocalRef(_E, ec);
}
void
-AcrThrow(JNI_STDENV, int cls, const char *msg)
+AcrThrowByName(JNI_STDENV, const char *cls, const char *msg)
{
jclass ec;
if (_E == 0)
_E = AcrGetJNIEnv();
+ if (cls == 0)
+ cls = "java/lang/Exception";
+ if (IS_INVALID_HANDLE(_E)) {
+ ACR_DEBUG_TRACE("JNI Environment is invalid or unavailable. Throwing
'%s'", cls);
+ if (msg) {
+ ACR_DEBUG_TRACE("%s", msg);
+ }
+ return;
+ }
+ if ((*_E)->ExceptionCheck(_E)) {
+ /* We already have a pending exception. */
+ ACR_DEBUG_TRACE("Exception is already in the queue. Throwing '%s'",
cls);
+ if (msg) {
+ ACR_DEBUG_TRACE("%s", msg);
+ }
+ return;
+ }
+ if ((ec = (*_E)->FindClass(_E, cls)) == 0) {
+ /* If the class cannot be found,
+ * the Exception has already been thrown.
+ * See JNI Find Class for the Exceptions thrown.
+ */
+ ACR_DEBUG_TRACE("Cannot find class '%s'", cls);
+ if (msg) {
+ ACR_DEBUG_TRACE("%s", msg);
+ }
+ return;
+ }
+ (*_E)->ThrowNew(_E, ec, msg);
+}
+
+void
+AcrThrow(JNI_STDENV, int cls, const char *msg)
+{
+ jclass ec = 0;
+
+ if (_E == 0)
+ _E = AcrGetJNIEnv();
if (cls < 0 && cls >= ACR_EX_LEN)
cls = 0;
if (IS_INVALID_HANDLE(_E)) {
@@ -623,6 +665,7 @@ AcrThrow(JNI_STDENV, int cls, const char
}
return;
}
+#if CACHE_THROWABLES
AcrLibLockAcquire();
if (_throw_classes[cls].clazz == 0) {
/* Create a global reference to the class.
@@ -633,9 +676,10 @@ AcrThrow(JNI_STDENV, int cls, const char
if (_throw_classes[cls].clazz == 0)
return;
(*_E)->DeleteLocalRef(_E, ec);
+ ec = _throw_classes[cls].clazz;
+#endif
}
- if (_throw_classes[cls].clazz != 0)
- (*_E)->ThrowNew(_E, _throw_classes[cls].clazz, msg);
+ (*_E)->ThrowNew(_E, ec, msg);
}
void
Added: commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c?rev=1086143&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c Mon Mar 28
07:37:39 2011
@@ -0,0 +1,123 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/observer.h"
+#include "acr/clazz.h"
+#include "acr/memory.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+ INVALID_FIELD_OFFSET,
+ 0,
+ 0,
+ 0,
+ "java/io/FileDescriptor"
+};
+
+J_DECLARE_M_ID(0000) = {
+ 0,
+ "<init>",
+ "()V"
+};
+
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "fd",
+ "I"
+};
+
+#if defined(WINDOWS)
+J_DECLARE_F_ID(0001) = {
+ -1,
+ -1,
+ 0,
+ "handle",
+ "J"
+};
+#endif
+
+ACR_CLASS_CTOR(FileDescriptor)
+{
+ int rv;
+
+ if ((rv = AcrLoadClass(_E, &_clazzn, 0)) != 0)
+ return rv;
+ J_LOAD_METHOD(0000);
+ J_LOAD_IFIELD(0000);
+#if defined(WINDOWS)
+ J_LOAD_IFIELD(0001);
+#endif
+ UNSAFE_OFF_IFIELD(0000);
+#if defined(WINDOWS)
+ UNSAFE_OFF_IFIELD(0001);
+#endif
+ _clazzn.u = 1;
+ return 0;
+}
+
+ACR_CLASS_DTOR(FileDescriptor)
+{
+ AcrUnloadClass(_E, &_clazzn);
+}
+
+int
+AcrFileDescriptorGetFd(JNI_STDARGS)
+{
+ int fd = -1;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return fd;
+ if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)_O;
+ if (oa != 0) {
+ char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0000));
+ fd = *((int *)fa);
+ }
+ }
+ else if (CLAZZ_LOADED) {
+ fd = GET_IFIELD_I(0000, _O);
+ }
+ return fd;
+}
+
+#if defined (WINDOWS)
+HANDLE
+AcrFileDescriptorGetHandle(JNI_STDARGS)
+{
+ HANDLE fh = INVALID_HANDLE_VALUE;
+
+ if (IS_JOBJECT_NULL(_E, _O))
+ return fh;
+ if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
+ char *oa = *(char **)_O;
+ if (oa != 0) {
+ char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0001));
+ fh = J2P(*((jlong *)fa), HANDLE);
+ }
+ }
+ else if (CLAZZ_LOADED) {
+ fh = GET_IFIELD_V(0001, _O, HANDLE);
+ }
+ return fh;
+}
+#endif
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/object.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/object.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Mon Mar 28
07:37:39 2011
@@ -19,7 +19,7 @@
#include "acr/string.h"
J_DECLARE_CLAZZ = {
- 0,
+ INVALID_FIELD_BASE,
0,
0,
0,
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/observer.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/observer.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/observer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/observer.c Mon Mar 28
07:37:39 2011
@@ -24,7 +24,7 @@
#include "acr/memory.h"
J_DECLARE_CLAZZ = {
- 0,
+ INVALID_FIELD_BASE,
0,
0,
0,
@@ -45,6 +45,7 @@ ACR_CLASS_CTOR(Observer)
return rv;
J_LOAD_METHOD(0000);
+ _clazzn.u = 1;
return 0;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon Mar 28
07:37:39 2011
@@ -19,7 +19,7 @@
#include "acr/clazz.h"
J_DECLARE_CLAZZ = {
- 0,
+ INVALID_FIELD_BASE,
0,
0,
0,
@@ -29,11 +29,17 @@ J_DECLARE_CLAZZ = {
J_DECLARE_M_ID(0000) = {
0,
"<init>",
- "([B)V"
+ "()V"
};
J_DECLARE_M_ID(0001) = {
0,
+ "<init>",
+ "([B)V"
+};
+
+J_DECLARE_M_ID(0002) = {
+ 0,
"getBytes",
"()[B"
};
@@ -46,6 +52,7 @@ ACR_CLASS_CTOR(String)
return rv;
J_LOAD_METHOD(0000);
J_LOAD_METHOD(0001);
+ J_LOAD_METHOD(0002);
_clazzn.u = 1;
return 0;
@@ -78,7 +85,7 @@ int
AcrGetNativeCodePage(const char *cs)
{
int i;
- if (cs && *cs) {
+ if (IS_VALID_STR(cs)) {
for (i = 0; iso_8859_1_aliases[i]; i++) {
if (strcasecmp(cs, iso_8859_1_aliases[i]) == 0)
return ACR_CP_ISO8859_1;
@@ -99,10 +106,10 @@ static char *get_string_iso_8859_1(JNIEn
{
jsize sl;
const jchar *sr;
- char *rv = 0;
+ char *rv;
sl = (*_E)->GetStringLength(_E, str);
- if (b && sl < ACR_MBUFF_LEN)
+ if (b && sl < ACR_PBUFF_LEN)
rv = b;
else {
rv = ACR_MALLOC(char, sl + 1);
@@ -112,6 +119,10 @@ static char *get_string_iso_8859_1(JNIEn
return 0;
}
}
+ if (sl == 0) {
+ *rv = '\0';
+ return rv;
+ }
sr = (*_E)->GetStringCritical(_E, str, 0);
if (!sr) {
if (rv != b)
@@ -657,18 +668,15 @@ static char *get_string_utf_8(JNIEnv *_E
{
jsize sl, nl;
const jchar *sr;
- char *rv = 0;
+ char *rv;
- if (!str) {
- return 0;
- }
if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
/* JNI out of memory error */
return 0;
}
sl = (*_E)->GetStringLength(_E, str);
nl = sl * 3;
- if (b && nl < ACR_MBUFF_LEN)
+ if (b && nl < ACR_PBUFF_LEN)
rv = b;
else {
rv = ACR_MALLOC(char, nl + 1);
@@ -678,6 +686,10 @@ static char *get_string_utf_8(JNIEnv *_E
return 0;
}
}
+ if (sl == 0) {
+ *rv = '\0';
+ return rv;
+ }
sr = (*_E)->GetStringCritical(_E, str, 0);
if (!sr) {
if (rv != b)
@@ -703,35 +715,47 @@ static char *get_string_utf_8(JNIEnv *_E
static char *get_string_default(JNIEnv *_E, jstring str, char *b)
{
jbyteArray sb = 0;
- char *rs = 0;
+ char *rv = 0;
if (!CLAZZ_LOADED) {
ACR_SET_OS_ERROR(ACR_EINIT);
return 0;
}
- sb = CALL_METHOD0(Object, 0001, str);
+ sb = CALL_METHOD0(Object, 0002, str);
if ((*_E)->ExceptionCheck(_E))
return 0;
else {
jint len = (*_E)->GetArrayLength(_E, sb);
if (b && len < ACR_PBUFF_LEN) {
/* Use provided stack storage */
- rs = b;
+ rv = b;
}
else {
- rs = ACR_MALLOC(char, len + 1);
- if (rs == 0) {
+ rv = ACR_MALLOC(char, len + 1);
+ if (rv == 0) {
(*_E)->DeleteLocalRef(_E, sb);
return 0;
}
}
- (*_E)->GetByteArrayRegion(_E, sb, 0, len, (jbyte *)rs);
- rs[len] = '\0'; /* NUL-terminate */
+ if (len > 0) {
+ /* Copy bytes to the provided buffer
+ */
+ (*_E)->GetByteArrayRegion(_E, sb, 0, len, (jbyte *)rv);
+ }
+ rv[len] = '\0'; /* NUL-terminate */
}
(*_E)->DeleteLocalRef(_E, sb);
- return rs;
+ return rv;
}
+static jstring new_string_zerolen(JNIEnv *_E)
+{
+ if (!CLAZZ_LOADED) {
+ ACR_SET_OS_ERROR(ACR_EINIT);
+ return 0;
+ }
+ return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000));
+}
static jstring new_string_default(JNIEnv *_E, const char *str)
{
jstring rs;
@@ -743,10 +767,13 @@ static jstring new_string_default(JNIEnv
return 0;
}
sl = (jsize)strlen(str);
+ if (sl == 0) {
+ return new_string_zerolen(_E);
+ }
ba = (*_E)->NewByteArray(_E, sl);
if (ba != 0) {
(*_E)->SetByteArrayRegion(_E, ba, 0, sl, (jbyte *)str);
- rs = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), ba);
+ rs = (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), ba);
(*_E)->DeleteLocalRef(_E, ba);
return rs;
}
@@ -756,24 +783,27 @@ static jstring new_string_default(JNIEnv
static jstring new_string_iso_8859_1(JNIEnv *_E, const char *s)
{
jstring rs = 0;
- jsize l = (jsize)strlen(s);
+ jsize sl = (jsize)strlen(s);
- if (l < ACR_MBUFF_SIZ) {
+ if (sl == 0) {
+ return new_string_zerolen(_E);
+ }
+ else if (sl < ACR_MBUFF_SIZ) {
jchar cc[ACR_MBUFF_SIZ];
jsize i;
- for (i = 0; i < l; i++) {
+ for (i = 0; i < sl; i++) {
cc[i] = s[i];
}
- rs = (*_E)->NewString(_E, cc, l);
+ rs = (*_E)->NewString(_E, cc, sl);
}
else {
jchar *cc;
- if ((cc = ACR_MALLOC(jchar, l + 1)) != 0) {
+ if ((cc = ACR_MALLOC(jchar, sl + 1)) != 0) {
size_t i;
- for (i = 0; i < l; i++) {
+ for (i = 0; i < sl; i++) {
cc[i] = s[i];
}
- rs = (*_E)->NewString(_E, cc, l);
+ rs = (*_E)->NewString(_E, cc, sl);
AcrFree(cc);
}
}
@@ -786,7 +816,10 @@ static jstring new_string_utf_8(JNIEnv *
int ex;
jsize sl = (jsize)strlen(s);
- if (sl < ACR_MBUFF_SIZ) {
+ if (sl == 0) {
+ return new_string_zerolen(_E);
+ }
+ else if (sl < ACR_MBUFF_SIZ) {
jchar cc[ACR_MBUFF_SIZ];
jsize wl = ACR_MBUFF_LEN;
if ((ex = conv_utf8_to_ucs2(s, sl, cc, &wl)) == ACR_SUCCESS)
@@ -834,6 +867,10 @@ AcrGetJavaStringW(JNIEnv *_E, jstring st
return 0;
}
}
+ if (sl == 0) {
+ *rv = L'\0';
+ return rv;
+ }
sr = (*_E)->GetStringCritical(_E, str, 0);
if (sr == 0) {
if (rv != b)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/system.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/system.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/system.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/system.c Mon Mar 28
07:37:39 2011
@@ -24,7 +24,7 @@
#include "acr/system.h"
J_DECLARE_CLAZZ = {
- 0,
+ INVALID_FIELD_BASE,
0,
0,
0,
@@ -52,7 +52,8 @@ ACR_CLASS_CTOR(System)
J_LOAD_MLOCAL(0000);
J_LOAD_MLOCAL(0001);
- return ACR_SUCCESS;
+ _clazzn.u = 1;
+ return 0;
}
ACR_CLASS_DTOR(System)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c?rev=1086143&r1=1086142&r2=1086143&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c Mon Mar 28
07:37:39 2011
@@ -19,7 +19,7 @@
#include "acr/string.h"
J_DECLARE_CLAZZ = {
- 0,
+ INVALID_FIELD_OFFSET,
0,
0,
0,
@@ -27,8 +27,8 @@ J_DECLARE_CLAZZ = {
};
J_DECLARE_F_ID(0000) = {
- 0,
- 0,
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
0,
"theUnsafe",
"Lsun/misc/Unsafe;"