summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBob Jamison <ishmalius@gmail.com>2008-04-03 13:23:49 +0000
committerishmal <ishmal@users.sourceforge.net>2008-04-03 13:23:49 +0000
commitc545b4c96b7b15cdaeb453f2bc77cbff0f04cdf5 (patch)
tree6aaeead38fd1162bea19bb6fa400eecedf0ff1ca /src
parentFixed LPE crash with unitialized pointer (diff)
downloadinkscape-c545b4c96b7b15cdaeb453f2bc77cbff0f04cdf5.tar.gz
inkscape-c545b4c96b7b15cdaeb453f2bc77cbff0f04cdf5.zip
Use MAX_PATH instead of arbitrary string length. Improve comments.
(bzr r5319)
Diffstat (limited to 'src')
-rw-r--r--src/bind/javabind.cpp72
1 files changed, 54 insertions, 18 deletions
diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp
index c62981f1f..fe9cff4df 100644
--- a/src/bind/javabind.cpp
+++ b/src/bind/javabind.cpp
@@ -106,6 +106,23 @@ String normalizePath(const String &str)
return buf;
}
+
+/**
+ * Convert a java string to a C++ string
+ */
+String getString(JNIEnv *env, jstring jstr)
+{
+ const char *chars = env->GetStringUTFChars(jstr, JNI_FALSE);
+ String str = chars;
+ env->ReleaseStringUTFChars(jstr, chars);
+ return str;
+}
+
+
+/**
+ * Check if the VM has encountered an Exception. If so, get the String for it
+ * and clear the exception
+ */
String getExceptionString(JNIEnv *env)
{
String buf;
@@ -115,9 +132,7 @@ String getExceptionString(JNIEnv *env)
jclass cls = env->GetObjectClass(exc);
jmethodID mid = env->GetMethodID(cls, "toString", "()Ljava/lang/String;");
jstring jstr = (jstring) env->CallObjectMethod(exc, mid);
- const char *str = env->GetStringUTFChars(jstr, JNI_FALSE);
- buf.append(str);
- env->ReleaseStringUTFChars(jstr, str);
+ buf.append(getString(env, jstr));
env->ExceptionClear();
return buf;
}
@@ -170,14 +185,6 @@ void setObjDouble(JNIEnv *env, jobject obj, const char *name, jdouble val)
env->SetDoubleField(obj, fid, val);
}
-String getString(JNIEnv *env, jstring jstr)
-{
- const char *chars = env->GetStringUTFChars(jstr, JNI_FALSE);
- String str = chars;
- env->ReleaseStringUTFChars(jstr, chars);
- return str;
-}
-
String getObjString(JNIEnv *env, jobject obj, const char *name)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "Ljava/lang/String;");
@@ -325,10 +332,13 @@ static const char *commonJavaPaths[] =
};
+/**
+ * Return the directory of the .exe that is currently running
+ */
static String getExePath()
{
- char exeName[80];
- GetModuleFileName(NULL, exeName, 80);
+ char exeName[MAX_PATH+1];
+ GetModuleFileName(NULL, exeName, MAX_PATH);
char *slashPos = strrchr(exeName, '\\');
if (slashPos)
*slashPos = '\0';
@@ -337,6 +347,10 @@ static String getExePath()
}
+/**
+ * Check a directory for several possibilities of sub-locations
+ * under it, where a jvm might exist.
+ */
static String checkPathUnderRoot(const String &root)
{
for (const char **path = commonJavaPaths ; *path ; path++)
@@ -356,13 +370,17 @@ static String checkPathUnderRoot(const String &root)
+/**
+ * Attempt to find and load a jvm.dll file. Find the createVM()
+ * function's address and return it
+ */
static CreateVMFunc getCreateVMFunc()
{
bool found = false;
String libname;
/**
- * First, look for an embedded jre in the $INKSCAPE dir.
+ * First, look for an embedded jre in the .exe's dir.
* This allows us to package our own JRE if we want to.
*/
String inkscapeHome = getExePath();
@@ -455,6 +473,10 @@ static CreateVMFunc getCreateVMFunc()
return createVM;
}
+/**
+ * Return the directory where the Java classes/libs/resources are
+ * located
+ */
static void getJavaRoot(String &javaroot)
{
javaroot = getExePath();
@@ -518,6 +540,10 @@ static bool findJVMRecursive(const String &dirpath,
}
+/**
+ * Some common places on a Unix filesystem where JVMs are
+ * often found.
+ */
static const char *commonJavaPaths[] =
{
"/usr/lib/jvm/jre",
@@ -529,6 +555,8 @@ static const char *commonJavaPaths[] =
NULL
};
+
+
/**
* Look for a Java VM (libjvm.so) in several Unix places
*/
@@ -572,6 +600,10 @@ static bool findJVM(String &result)
+/**
+ * Attempt to find and load a jvm.dll file. Find the createVM()
+ * function's address and return it
+ */
static CreateVMFunc getCreateVMFunc()
{
String libname;
@@ -597,6 +629,10 @@ static CreateVMFunc getCreateVMFunc()
}
+/**
+ * Return the directory where the Java classes/libs/resources are
+ * located
+ */
static void getJavaRoot(String &javaroot)
{
javaroot = INKSCAPE_BINDDIR;
@@ -684,9 +720,9 @@ static void populateClassPath(const String &javaroot,
* This is provided to scripts can grab the current copy or the
* repr tree. If anyone has a smarter way of doing this, please implement.
*/
-jstring JNICALL documentGet(JNIEnv *env, jobject /*obj*/, jlong ptr)
+jstring JNICALL documentGet(JNIEnv *env, jobject /*obj*/, jlong /*ptr*/)
{
- JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ //JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
String buf = sp_repr_save_buf((SP_ACTIVE_DOCUMENT)->rdoc);
jstring jstr = env->NewStringUTF(buf.c_str());
return jstr;
@@ -696,9 +732,9 @@ jstring JNICALL documentGet(JNIEnv *env, jobject /*obj*/, jlong ptr)
* This is provided to scripts can load an XML tree into Inkscape.
* If anyone has a smarter way of doing this, please implement.
*/
-jboolean JNICALL documentSet(JNIEnv *env, jobject /*obj*/, jlong ptr, jstring jstr)
+jboolean JNICALL documentSet(JNIEnv *env, jobject /*obj*/, jlong /*ptr*/, jstring jstr)
{
- JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ //JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
String s = getString(env, jstr);
SPDocument *doc = sp_document_new_from_mem(s.c_str(), s.size(), true);
}