Commits

camlspotter committed ea42fe6

from python bug fix

Comments (0)

Files changed (4)

 ################################################################## C BUILD RULE
 
 PY_PREFIX=/usr
-PY_VERSION=2.6
+PY_VERSION=2.7
 CFLAGS+= -fPIC -I $(OCAML_WHERE) -I $(PY_PREFIX)/include/python$(PY_VERSION)
 
 IDLS[] = 
 clean:
   rm -f $(filter-proper-targets $(ls R, .))
 
-MyOCamlPackage(opycaml, utils type autoapi api, auto_stubs api_ml, -lpython2.6 -L$(PREFIX)/lib/ocaml -lcamlidl)
+MyOCamlPackage(opycaml, utils type autoapi api, auto_stubs api_ml, -lpython$(PY_VERSION) -L$(PREFIX)/lib/ocaml -lcamlidl)
 
 opycaml_python.o: opycaml.cmx libopycaml.a dllopycaml.so
-	$(OCamlOpt) -output-obj -o $@ opycaml.cmx -cclib -lopycaml -ccopt -L$(OCAML_WHERE) -ccopt -Wl,-rpath,$(OCAML_WHERE) -cclib -lpython2.6 -cclib -lcamlidl 
+	$(OCamlOpt) -output-obj -o $@ opycaml.cmx -cclib -lopycaml -ccopt -L$(OCAML_WHERE) -ccopt -Wl,-rpath,$(OCAML_WHERE) -cclib -lpython$(PY_VERSION) -cclib -lcamlidl 
 
 .DEFAULT: opycaml.cma opycaml.cmxa opycaml_python.o
 
       | Not_found of _Object t
     
     let callback : _Object t option -> _Tuple t -> result = fun self_option args_tuple ->
+      prerr_endline "Opycaml.Api.Callback.callback is called!";
       let args = Tuple.to_list args_tuple in
       match args with
       | [] -> assert false
     external python_init : unit -> unit = "opycaml_init_callback"
 
     let initialize () = 
+      prerr_endline "Opycaml.Api.Callback.initialize()...";
       OCaml.Callback.register "( ゚∀゚)o彡°O'PyCaml callback" callback;
       OCaml.Callback.register "( ゚∀゚)o彡°O'PyCaml closure callback" closure_callback;
       python_init ()
       external address : [>_Object] t -> nativeint = "opycaml_address"
     
       external internal_init : unit -> unit = "opycaml_init"
+      let initialized = ref false
       let initialize () =
-        OCaml.Callback.register_exception "( ゚∀゚)o彡°O'PyCaml exception" (Error (poly_none (), poly_none ()));
-        internal_init ();
-        _internal_initialize ();
-        Callback.initialize ()
+        if not !initialized then begin
+          initialized := true;
+          OCaml.Callback.register_exception "( ゚∀゚)o彡°O'PyCaml exception" (Error (poly_none (), poly_none ()));
+          internal_init ();
+          if Sys.argv.(0) <> "from python" then _internal_initialize ();
+          Callback.initialize ()
+        end
       ;;
-    
+
       let debug name o =
         let cnt = refcnt o in
         let repr = String.asString (Object.repr o) in
 module Object = Object
 module Err = Err
 module Int = Int
+
+let _ = Base.initialize ()
 PyObject *opycaml_callback( PyObject *self, PyObject *args_tuple) {
     value out;
 
+    fprintf(stderr, "OPyCaml opycaml_callback\n");
+
     static value * closure_p = NULL;
     if (closure_p == NULL) {
         /* First time around, look up by name */
     }
 }
 
-static PyMethodDef OPyCamlMethods[] = {
+/* static */ PyMethodDef OPyCamlMethods[] = {
     { "ocaml", opycaml_callback, METH_VARARGS, "Call registered OCaml functions" }, // static method
     { NULL, NULL, 0, NULL }
 };
 
-PyMODINIT_FUNC initopycaml(void)
+PyMODINIT_FUNC initopycaml_from_ocaml(void)
 {
+    fprintf(stderr, "OPyCaml initopycaml_from_ocaml\n");
     (void) Py_InitModule("opycaml", OPyCamlMethods);
 }
 
+// Use for OCaml program. Not for Python uses OCaml 
 CAMLprim void opycaml_init_callback(void)
 {
-    initopycaml();
+    initopycaml_from_ocaml();
 }
 
 // Having OCaml value inside Python
 module1 = Extension('opycaml',
                     sources = ['opycaml_ext.c'],
                     libraries = ['asmrun', 'camlidl'],
-                    extra_objects = ['../opycaml_python.o', '../api_ml.o', '../auto_stubs.o'],
+                    extra_objects = ['../opycaml_python.o', '../api_ml.o', '../from_python_c.o', '../auto_stubs.o'],
                     library_dirs = ['/home/jfuruse/.share/prefix/lib/ocaml', '/usr/lib/ocaml'])
 
 setup ( name = 'OPyCaml',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.