Commits

camlspotter committed 404bd09 Draft

patch from ojacare is applied

  • Participants
  • Parent commits 8a48959
  • Branches original
  • Tags original-camljava-0.3-ojacare-20051116

Comments (0)

Files changed (19)

File camljava-0.3/Makefile

 all:
 	cd lib; $(MAKE) all
 
+opt:
+	cd lib; $(MAKE) opt
+
 install:
 	cd lib; $(MAKE) install
 

File camljava-0.3/Makefile.config.mingw

+################### C compiler ########################
+
+# C compiler to use
+CC=gcc -mno-cygwin
+
+# Flags for $(CC)
+CFLAGS=-O -g -Wall -Wno-unused -mms-bitfields
+
+################### Java compiler #####################
+
+# Java compiler to use
+JAVAC=javac -g
+
+################### JNI interface #####################
+
+## Defaults are set for Sun's JDK 1.2.2 under Linux.  
+## For other platforms, adjust as required and tell us about it.
+
+# Home location for the JDK.  Only used for setting other variables below. 
+JDKHOME=C:/Program\ Files/Java/j2sdk1.4.2_04
+
+# Where to find the JNI include files (for compiling the OCaml-JNI C stubs)
+JNIINCLUDES=-I$(JDKHOME)/include -I$(JDKHOME)/include/win32
+
+# The library to link with to get the JNI
+JNILIBS=-ljvm
+JNIPATH=$(JDKHOME)/jre/bin/client/jvm.dll
+
+# Additional link-time options to pass to $(CC) when linking with $(JNILIBS)
+JNILIBOPTS=-Wl,-rpath,`ocamlc -where`/camljava
+	
+
+JNISTUBSOPTIONS=

File camljava-0.3/Makefile.config.msvc

 ################### Java compiler #####################
 
 # Java compiler to use
-JAVAC=javac -g
+JAVAC=javac
 
 ################### JNI interface #####################
 

File camljava-0.3/Makefile.config.osx

+################### C compiler ########################
+
+# C compiler to use
+CC=gcc
+
+# Flags for $(CC)
+CFLAGS=-O -Wall
+
+################### Java compiler #####################
+
+# Java compiler to use
+JAVAC=javac
+
+################### JNI interface #####################
+
+## Defaults are set for MacOS X 10.2
+
+# Where to find the JNI include files (for compiling the OCaml-JNI C stubs)
+JNIINCLUDES=-I/System/Library/Frameworks/JavaVM.framework/Versions/CurrenCurrentt/Headers
+
+# The library to link with to get the JNI
+JNILIBS=-framework JavaVM
+
+# Additional link-time options to pass to $(CC) when linking with $(JNILIBS)
+JNILIBOPTS=

File camljava-0.3/Makefile.mingw

+MK=$(MAKE) -f Makefile.mingw
+
+all:
+	cd lib; $(MK) all
+
+opt:
+	cd lib; $(MK) opt
+
+install:
+	cd lib; $(MK) install
+
+tst:
+	cd test; $(MK) 
+
+clean:
+	cd lib; $(MK)  clean
+	cd test; $(MK) clean

File camljava-0.3/Makefile.msvc

 all:
 	cd lib; $(MK) all
 
+opt:
+	cd lib; $(MK) opt
+
 install:
 	cd lib; $(MK) install
 

File camljava-0.3/Makefile.osx

+MK=$(MAKE) -f Makefile.osx
+
+all:
+	cd lib; $(MK) all
+
+opt:
+	cd lib; $(MK) opt
+
+install:
+	cd lib; $(MK) install
+
+tst:
+	cd test; $(MK)
+
+clean:
+	cd lib; $(MK) clean
+	cd test; $(MK) clean

File camljava-0.3/lib/Makefile

 OCAMLLIB=`ocamlc -where`
 CAMLJAVALIB=$(OCAMLLIB)/camljava
 
-all: jni.cma jni.cmxa javaclasses
+all: jni.cma javaclasses
+opt: jni.cmxa javaclasses
 
 install:
 	mkdir -p $(CAMLJAVALIB)
-	cp jni.cma jni.cmi jni.cmxa jni.a libcamljni.a jni.mli $(CAMLJAVALIB)
+	if test -f jni.cmxa; then cp jni.cmxa jni.a $(CAMLJAVALIB); fi
+	cp jni.cma jni.cmi libcamljni.a jni.mli $(CAMLJAVALIB)
 	jar cf $(CAMLJAVALIB)/camljava.jar fr/inria/caml/camljava/*.class
+	cp ../Makefile.config $(CAMLJAVALIB)
 
 jni.cma: jni.cmo libcamljni.a
 	$(OCAMLC) -linkall -a -o jni.cma -custom jni.cmo \

File camljava-0.3/lib/Makefile.mingw

+include ../Makefile.config.mingw
+
+OCAMLC=ocamlc -g
+OCAMLOPT=ocamlopt
+OCAMLDEP=ocamldep
+OCAMLLIB=`ocamlc -where`
+CAMLJAVALIB=$(OCAMLLIB)/camljava
+
+all: libjvm.dll.a jni.cma javaclasses
+opt: libjvm.dll.a jni.cmxa javaclasses
+
+install:
+	mkdir -p $(CAMLJAVALIB)
+	if test -f jni.cmxa; then cp jni.cmxa jni.a; fi
+	cp jni.cma jni.cmi libcamljni.a jni.mli libjvm.dll.a $(CAMLJAVALIB)
+	jar cf $(CAMLJAVALIB)/camljava.jar fr/inria/caml/camljava/*.class
+
+jni.cma: jni.cmo libcamljni.a
+	$(OCAMLC) -linkall -a -o jni.cma -custom jni.cmo \
+            -ccopt "$(JNILIBOPTS)" -cclib -lcamljni -cclib "$(JNILIBS)"
+
+jni.cmxa: jni.cmx libcamljni.a
+	$(OCAMLOPT) -linkall -a -o jni.cmxa jni.cmx \
+            -ccopt "$(JNILIBOPTS)" -cclib -lcamljni -cclib "$(JNILIBS)"
+
+libcamljni.a: jnistubs.o
+	rm -f libcamljni.a
+	ar rcs libcamljni.a jnistubs.o
+
+
+libjvm.dll.a: jvm.def
+	dlltool --input-def jvm.def --kill-at --dllname $(JNIPATH) --output-lib libjvm.dll.a
+
+clean::
+	rm -f libcamljni.a
+
+jni.ml: jni.mlp jni.mli ../Makefile.config
+	rm -f jni.ml
+	sed -e 's|%PATH%|'$(CAMLJAVALIB)/camljava.jar'|' \
+                jni.mlp > jni.ml
+	chmod -w jni.ml
+
+clean::
+	rm -f jni.ml
+
+beforedepend:: jni.ml
+
+javaclasses:
+	$(JAVAC) fr/inria/caml/camljava/*.java
+
+clean::
+	rm -f fr/inria/caml/camljava/*.class
+
+clean::
+	rm -f *.cm? *.[oa]
+
+.SUFFIXES: .ml .mli .cmo .cmi .cmx
+
+.c.o:
+	$(CC) -c $(CFLAGS) $(JNIINCLUDES) -I$(OCAMLLIB) $*.c
+
+.ml.cmo:
+	$(OCAMLC) -c $*.ml
+
+.ml.cmx:
+	$(OCAMLOPT) -c $*.ml
+
+.mli.cmi:
+	$(OCAMLC) -c $*.mli
+
+depend: beforedepend
+	$(OCAMLDEP) *.mli *.ml > .depend
+
+include .depend
+

File camljava-0.3/lib/Makefile.msvc

 OCAMLLIB=`ocamlc -where`
 CAMLJAVALIB=$(OCAMLLIB)/camljava
 
-all: jni.cma jni.cmxa javaclasses
+all: jni.cma javaclasses
+opt: jni.cmxa javaclasses
 
 install:
 	mkdir -p $(CAMLJAVALIB)
-	cp jni.cma jni.cmi jni.cmxa jni.lib libcamljni.lib jni.mli $(CAMLJAVALIB)
+	if test -f jni.cmxa; then cp jni.cmxa jni.lib $(CAMLJAVALIB); fi
+	cp jni.cma jni.cmi libcamljni.lib jni.mli $(CAMLJAVALIB)
 	jar cf $(CAMLJAVALIB)/camljava.jar fr/inria/caml/camljava/*.class
+	cp ../Makefile.config.msvc $(CAMLJAVALIB)/Makefile.config
 
 jni.cma: jni.cmo libcamljni.lib
 	$(OCAMLC) -linkall -a -o jni.cma -custom jni.cmo \

File camljava-0.3/lib/Makefile.osx

+include ../Makefile.config.osx
+
+OCAMLC=ocamlc.opt -g
+OCAMLOPT=ocamlopt
+OCAMLDEP=ocamldep
+OCAMLLIB=`ocamlc -where`
+CAMLJAVALIB=$(OCAMLLIB)/camljava
+
+all: jni.cma javaclasses
+opt: jni.cmxa javaclasses
+
+install:
+	mkdir -p $(CAMLJAVALIB)
+	if test -f jni.cmxa; then cp jni.cmxa jni.a $(CAMLJAVALIB); fi
+	cp jni.cma jni.cmi libcamljni.a jni.mli $(CAMLJAVALIB)
+	jar cf $(CAMLJAVALIB)/camljava.jar fr/inria/caml/camljava/*.class
+	ranlib $(CAMLJAVALIB)/libcamljni.a 
+	if test -f jni.a; then ranlib $(CAMLJAVALIB)/jni.a; fi
+	cp ../Makefile.config.osx $(CAMLJAVALIB)/Makefile.config
+
+jni.cma: jni.cmo libcamljni.a
+	$(OCAMLC) -linkall -a -o jni.cma -custom jni.cmo \
+            -ccopt "$(JNILIBOPTS)" -cclib -lcamljni -cclib "$(JNILIBS)"
+
+jni.cmxa: jni.cmx libcamljni.a
+	$(OCAMLOPT) -linkall -a -o jni.cmxa jni.cmx \
+            -ccopt "$(JNILIBOPTS)" -cclib -lcamljni -cclib "$(JNILIBS)"
+
+libcamljni.a: jnistubs.o
+	rm -f libcamljni.a
+	ar rcs libcamljni.a jnistubs.o
+
+clean::
+	rm -f libcamljni.a
+
+jni.ml: jni.mlp jni.mli ../Makefile.config
+	rm -f jni.ml
+	sed -e 's|%PATH%|'$(CAMLJAVALIB)/camljava.jar'|' \
+                jni.mlp > jni.ml
+	chmod -w jni.ml
+
+clean::
+	rm -f jni.ml
+
+beforedepend:: jni.ml
+
+javaclasses:
+	$(JAVAC) fr/inria/caml/camljava/*.java
+
+clean::
+	rm -f fr/inria/caml/camljava/*.class
+
+clean::
+	rm -f *.cm? *.[oa]
+
+.SUFFIXES: .ml .mli .cmo .cmi .cmx
+
+.c.o:
+	$(CC) -c $(CFLAGS) $(JNIINCLUDES) -I$(OCAMLLIB) $*.c
+
+.ml.cmo:
+	$(OCAMLC) -c $*.ml
+
+.ml.cmx:
+	$(OCAMLOPT) -c $*.ml
+
+.mli.cmi:
+	$(OCAMLC) -c $*.mli
+
+depend: beforedepend
+	$(OCAMLDEP) *.mli *.ml > .depend
+
+include .depend
+

File camljava-0.3/lib/jni.mli

 (*                                                                     *)
 (***********************************************************************)
 
-(* $Id: jni.mli,v 1.1 2001/06/05 12:19:55 xleroy Exp $ *)
+(* $Id: jni.mli,v 1.1.1.1 2004/07/19 11:10:24 henry Exp $ *)
 
 (* Low-level Java interface (JNI level) *)
 

File camljava-0.3/lib/jni.mlp

 (*                                                                     *)
 (***********************************************************************)
 
-(* $Id: jni.mlp,v 1.3 2003/02/20 13:42:40 xleroy Exp $ *)
+(* $Id: jni.mlp,v 1.1.1.1 2004/07/19 11:10:24 henry Exp $ *)
 
 (* Low-level Java interface (JNI level) *)
 
       "Unix" -> ":"
     | "Win32" -> ";"
     | _ -> assert false in
+  let path = libpath ^ sep ^ "." in
   let path =
     try
-      Sys.getenv "CLASSPATH" ^ sep ^ libpath
+      Sys.getenv "CLASSPATH" ^ sep ^ path
     with Not_found ->
-      libpath in
+      path in
   init path;
   at_exit shutdown
 

File camljava-0.3/lib/jnistubs.c

 #define Val_jboolean(b) ((b) == JNI_FALSE ? Val_false : Val_true)
 #define Jboolean_val(v) (Val_bool(v) ? JNI_TRUE : JNI_FALSE)
 
+/**********Threading *************/
+
+static JNIEnv * g_jenv;
+
+void init_threading() {
+  g_jenv = jenv;
+}
+
+void camljava_check_main_thread() {
+  if(jenv != g_jenv) {
+    fprintf(stderr,"Pas de callback depuis un thread autre que le thread principal pour l'instant !!!\n");
+    fflush(stderr);
+    // lever une exception Java serait mieux    
+    exit(2);
+  }
+  return;
+}
+
 /************ Wrapping of Java objects as Caml values *************/
 
 #define JObject(v) (*((jobject *) Data_custom_val(v)))
   retcode = JNI_CreateJavaVM(&jvm, (void **) &jenv, &vm_args);
   stat_free(classpath);
   if (retcode < 0) failwith("Java.init");
+  init_threading(); // Ajout O'Jacare
   return Val_unit;
 }
 
 
   savedenv = jenv;
   jenv = env;
+
+  camljava_check_main_thread(); // Ajout O'Jacare
+
   if (!caml_classes_initialized) {
     if (init_caml_classes(env) == -1) return -1;
     caml_classes_initialized = 1;
       else if ((*env)->IsInstanceOf(env, arg, caml_double))
         carg = copy_double((*env)->GetDoubleField(env, arg,
                                                 caml_double_contents));
-      else if ((*env)->IsInstanceOf(env, arg, java_lang_string))
-        carg = extract_java_string(env, (jstring) arg);
+      /*      else if ((*env)->IsInstanceOf(env, arg, java_lang_string))
+	      carg = extract_java_string(env, (jstring) arg); */
       else
         carg = alloc_jobject(arg);
       cargs[i] = carg;

File camljava-0.3/lib/jvm.def

+EXPORTS
+JNI_CreateJavaVM@12
+JNI_GetDefaultJavaVMInitArgs@4
+JNI_GetCreatedJavaVMs@12

File camljava-0.3/test/Makefile

 	$(JAVAC) -classpath $(CAMLJAVA):. $*.java
 
 clean::
-	rm -f *.cm?
+	rm -f *.cm? *.class

File camljava-0.3/test/Makefile.mingw

+include ../Makefile.config.mingw
+
+CAMLJAVA=`ocamlc -where`/camljava/camljava.jar
+
+all: jnitest Test.class Testcb.class
+	./jnitest
+
+jnitest: jnitest.ml
+	ocamlc -ccopt -g -o jnitest -I +camljava jni.cma jnitest.ml 
+
+clean::
+	rm -f jnitest.exe
+
+.SUFFIXES: .java .class
+
+.java.class:
+	$(JAVAC) -classpath "$(CAMLJAVA);." $*.java
+
+clean::
+	rm -f *.cm? 

File camljava-0.3/test/Makefile.msvc

 	$(JAVAC) -classpath "$(CAMLJAVA);." $*.java
 
 clean::
-	rm -f *.cm?
+	rm -f *.cm? *.class

File camljava-0.3/test/Makefile.osx

+include ../Makefile.config.osx
+
+CAMLJAVA=`ocamlc -where`/camljava/camljava.jar
+
+all: jnitest Test.class Testcb.class
+	./jnitest
+
+jnitest: jnitest.ml
+	ocamlc -ccopt -g -o jnitest -I +camljava jni.cma jnitest.ml
+
+clean::
+	rm -f jnitest
+
+.SUFFIXES: .java .class
+
+.java.class:
+	$(JAVAC) -classpath $(CAMLJAVA):. $*.java
+
+clean::
+	rm -f *.cm? *.class