[kaffe] Problem with JNI...

Timothy Stack stack@cs.utah.edu
Tue, 4 Jun 2002 13:09:25 -0600 (MDT)


--%--multipart-mixed-boundary-2.7507.1023217765--%
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

> Hi!

hi again,

It looks like i forgot to add some code needed by some other changes, can
you try the attached patch and see if it works.  You'll need to run
developers/autogen.sh because theres a configure.in change.

> regards Martin

sorry about the inconvenience,

tim stack

--%--multipart-mixed-boundary-2.7507.1023217765--%
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Description: ascii text
Content-Disposition: attachment; filename="ext.diff"

Index: acinclude.m4
===================================================================
RCS file: /cvs/kaffe/kaffe/acinclude.m4,v
retrieving revision 1.22
diff -u -r1.22 acinclude.m4
--- acinclude.m4	6 May 2002 02:59:55 -0000	1.22
+++ acinclude.m4	4 Jun 2002 19:00:13 -0000
@@ -3451,6 +3451,26 @@
 ])
 
 
+# AC_LTDL_SHLIBEXT
+# ----------------
+AC_DEFUN(AC_LTDL_SHLIBEXT,
+[AC_REQUIRE([_LT_AC_LTCONFIG_HACK])
+AC_CACHE_CHECK([which extension is used for shared libraries],
+  libltdl_cv_shlibext,
+[ac_last=
+  for ac_spec in $library_names_spec; do
+    ac_last="$ac_spec"
+  done
+  echo "$ac_last" | [sed 's/\[.*\]//;s/^[^.]*//;s/\$.*$//;s/\.$//'] > conftest
+libltdl_cv_shlibext=`cat conftest`
+rm -f conftest
+])
+if test -n "$libltdl_cv_shlibext"; then
+  AC_DEFINE_UNQUOTED(LTDL_SHLIB_EXT, "$libltdl_cv_shlibext",
+    [Define to the extension used for shared libraries, say, ".so". ])
+fi
+])# AC_LTDL_SHLIBEXT
+
 # AC_PROG_NM - find the path to a BSD-compatible name lister
 AC_DEFUN([AC_PROG_NM],
 [AC_REQUIRE([_LT_AC_LIBTOOL_SYS_PATH_SEPARATOR])dnl
Index: configure.in
===================================================================
RCS file: /cvs/kaffe/kaffe/configure.in,v
retrieving revision 1.164
diff -u -r1.164 configure.in
--- configure.in	2 Jun 2002 16:02:57 -0000	1.164
+++ configure.in	4 Jun 2002 19:00:24 -0000
@@ -130,6 +130,7 @@
 
 AC_LIBTOOL_DLOPEN
 AC_LIBLTDL_CONVENIENCE
+AC_REQUIRE([AC_LTDL_SHLIBEXT])
 AC_PROG_LIBTOOL
 AC_SUBST(LIBTOOL_DEPS)
 AC_SUBST(LIBLTDL)
Index: external.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/external.c,v
retrieving revision 1.39
diff -u -r1.39 external.c
--- external.c	3 Aug 2001 17:38:49 -0000	1.39
+++ external.c	4 Jun 2002 19:00:41 -0000
@@ -66,7 +66,7 @@
 #endif
 
 #ifndef LIBRARYLOAD
-#define LIBRARYLOAD(desc,filename)	((desc)=lt_dlopenext((filename)))
+#define LIBRARYLOAD(desc,filename)	((desc)=lt_dlopen((filename)))
 #endif
 
 #ifndef LIBRARYUNLOAD
@@ -184,6 +184,24 @@
 	return( retval );
 }
 
+/* Standard libtool archive file extension.  */
+#undef  LTDL_ARCHIVE_EXT
+#define LTDL_ARCHIVE_EXT	".la"
+
+static char *libSuffixes[] = {
+	LTDL_ARCHIVE_EXT,
+#ifdef LTDL_SHLIB_EXT
+	LTDL_SHLIB_EXT,
+#endif
+	0
+};
+
+enum {
+	TRY_LOAD_FOUND,
+	TRY_LOAD_NOT_FOUND,
+	TRY_LOAD_ERROR,
+};
+
 /*
  * Link in a native library. If successful, returns an index >= 0 that
  * can be passed to unloadNativeLibrary(). Otherwise, returns -1 and
@@ -193,7 +211,7 @@
 loadNativeLibrary2(char* path, int default_refs, char *errbuf, size_t errsiz)
 {
 	struct _libHandle *lib;
-	int index;
+	int index, status;
 
 	/* Find a library handle.  If we find the library has already
 	 * been loaded, don't bother to get it again, just increase the
@@ -236,25 +254,59 @@
 /* if we tested for existence here, libltdl wouldn't be able to look
    for system-dependent library names */
 
+	lib->name = KMALLOC(strlen(path)
+			    + 16 /* XXX extension */
+			    + 1);
+	
 	blockAsyncSignals();
-	LIBRARYLOAD(lib->desc, path);
+	{
+		int lpc;
+
+		status = TRY_LOAD_NOT_FOUND;
+		for( lpc = 0;
+		     (status == TRY_LOAD_NOT_FOUND) && libSuffixes[lpc];
+		     lpc++ )
+		{
+			sprintf(lib->name, "%s%s", path, libSuffixes[lpc]);
+			LIBRARYLOAD(lib->desc, lib->name);
+			if( lib->desc )
+			{
+				status = TRY_LOAD_FOUND;
+			}
+			else
+			{
+				const char *err = LIBRARYERROR();
+				
+				/* XXX Bleh, silly guessing system. */
+				if( err == 0 )
+				{
+					status = TRY_LOAD_ERROR;
+					strncpy(errbuf,
+						"Unknown error",
+						errsiz);
+				}
+				else if( (strstr(err, "ile not found") ||
+					  strstr(err, "annot open")) )
+				{
+					status = TRY_LOAD_NOT_FOUND;
+				}
+				else
+				{
+					/* We'll assume its a real error. */
+					status = TRY_LOAD_ERROR;
+					strncpy(errbuf, err, errsiz);
+				}
+			}
+		}
+	}
 	unblockAsyncSignals();
 
 	if (lib->desc == 0) {
-		const char *err = LIBRARYERROR();
-
-		if (err == 0) {
-			err = "Unknown error";
-		}
-		if (errbuf != 0) {
-			strncpy(errbuf, err, errsiz);
-			errbuf[errsiz - 1] = '\0';
-		}
+		errbuf[errsiz - 1] = '\0';
 		return -1;
 	}
 
 	lib->ref = default_refs;
-	lib->name = KMALLOC(strlen(path) + 1);
 	addToCounter(&ltmem, "vmmem-libltdl", 1, GCSIZEOF(lib->name));
 	strcpy(lib->name, path);
 

--%--multipart-mixed-boundary-2.7507.1023217765--%--