Commits

seanmcl committed 0f2435f

ocaml_inotify as packed module

Comments (0)

Files changed (6)

ocaml/contrib/ocaml_inotify/Makefile

+
 OCAMLC = ocamlc
 OCAMLOPT = ocamlopt
 
-OCAMLOPTFLAGS =
+# inotify.cmxa: inotify_stubs.o inotify.cmx inotify.cmo
+#	ocamlmklib -o inotify inotify_stubs.o inotify.cmx inotify.cmo
+#	ocamlopt -pack -o ocaml_inotify.cmxa unix.cmxa inotify_stubs.o inotify.cmx
 
-OCAMLABI := $(shell ocamlc -version)
-OCAMLLIBDIR := $(shell ocamlc -where)
-OCAMLDESTDIR ?= $(OCAMLLIBDIR)
+# inotify.cma: inotify_stubs.o inotify.cmx inotify.cmo
+# 	ocamlmklib -o inotify unix.cma inotify_stubs.o inotify.cmx inotify.cmo
 
-OCAML_TEST_INC = -I `ocamlfind query oUnit`
-OCAML_TEST_LIB = `ocamlfind query oUnit`/oUnit.cmxa
+# inotify.cma: inotify_stubs.o inotify.cmo
+#	ocamlc -pack -o $@ inotify.cmo inotify_stubs.o
+#	ocamlc -pack -o $@ inotify.cmo inotify_stubs.o
+#	ar rc libinotify.a inotify_stubs.o
 
-LIBS = inotify.cmi inotify.cmxa inotify.cma
-PROGRAMS = test.inotify
+# inotify.cma: inotify_stubs.o inotify.cmx inotify.cmo
+# 	ocamlmklib -v -o inotify unix.cma inotify_stubs.o inotify.cmx inotify.cmo
 
-PKG_NAME = inotify
+# inotify.cmxa: inotify_stubs.o inotify.cmi inotify.cmo inotify.cmx
+# 	gcc -bundle -flat_namespace -undefined suppress -o dllinotify.so inotify_stubs.o
+# 	ar cq libinotify.a inotify_stubs.o
+# 	ranlib libinotify.a
+# 	ocamlc -a -o inotify.cma unix.cma inotify.cmo -dllib -linotify -cclib -linotify
+# 	ocamlopt -a -o inotify.cmxa inotify.cmx -cclib -linotify
 
-all: $(LIBS)
+OCAMLFLAGS = -for-pack Ocaml_inotify
 
-all-byte: inotify.cmi inotify.cma
+all: ocaml_inotify.cmxa test.inotify
 
-all-opt: inotify.cmi inotify.cmxa inotify.cma
-
-bins: $(PROGRAMS)
-
-libs: $(LIBS)
-
-inotify.cmxa: inotify_stubs.o inotify.cmx inotify.cmo
-	ocamlmklib -o inotify inotify_stubs.o inotify.cmx inotify.cmo
+ocaml_inotify.cmxa: inotify_stubs.o inotify.cmi inotify.cmo inotify.cmx
+	gcc -bundle -flat_namespace -undefined suppress -o dllocaml_inotify_stubs.so inotify_stubs.o
+	ar cq libocaml_inotify_stubs.a inotify_stubs.o
+	ranlib libocaml_inotify_stubs.a
+	ocamlopt -pack -o ocaml_inotify.cmx inotify.cmx
+	ocamlopt -a -o ocaml_inotify.cmxa ocaml_inotify.cmx -cclib -locaml_inotify_stubs
+	ocamlc -pack -o ocaml_inotify.cmo inotify.cmo
+	ocamlc -a -o ocaml_inotify.cma unix.cma ocaml_inotify.cmo -dllib -locaml_inotify_stubs -cclib -locaml_inotify_stubs
 
 %.cmo: %.ml
-	$(OCAMLC) -c -o $@ $<
+	$(OCAMLC) $(OCAMLFLAGS) -c -o $@ $<
 
 %.cmi: %.mli
-	$(OCAMLC) -c -o $@ $<
+	$(OCAMLC) $(OCAMLFLAGS) -c -o $@ $<
 
 %.cmx: %.ml
-	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c -o $@ $<
+	$(OCAMLOPT) $(OCAMLFLAGS) -c -o $@ $<
 
 %.o: %.c
 	$(OCAMLC) -c -o $@ $<
 
 OCAMLFIND_INSTALL_FLAGS ?= -destdir $(OCAMLDESTDIR) -ldconf ignore
+OCAMLLIBDIR := $(shell ocamlc -where)
+OCAMLDESTDIR ?= $(OCAMLLIBDIR)
+PKG_NAME = ocaml_inotify
 
 .PHONY: install
+
 install: $(LIBS)
 	ocamlfind install $(OCAMLFIND_INSTALL_FLAGS) $(PKG_NAME) META inotify.cmi inotify.mli inotify.cma inotify.cmxa *.a *.so *.cmx
 
 uninstall:
 	ocamlfind remove $(OCAMLFIND_INSTALL_FLAGS) $(PKG_NAME)
 
-test.inotify: inotify.cmxa test.inotify.ml
+test.inotify: ocaml_inotify.cmxa test.inotify.ml
 	$(OCAMLOPT) -I . -o $@ unix.cmxa $+
 
 clean:

ocaml/contrib/ocaml_inotify/inotify_stubs.c

 #else
 
 value stub_inotify_init(value unit){
-  CAMLparam1(unit);
-  CAMLreturn(Val_int(-1));
+  caml_invalid_argument("stub_inotify_init unimplemented");
 }
 
 value stub_inotify_add_watch(value fd, value path, value mask){
-  CAMLparam3(fd, path, mask);
-  CAMLreturn(Val_int(-1));
+  caml_invalid_argument("stub_inotify_add_watch unimplemented");
 }
 
 value stub_inotify_rm_watch(value fd, value wd){
-  CAMLparam2(fd, wd);
-  CAMLreturn(Val_unit);
+  caml_invalid_argument("stub_inotify_rm_watch unimplemented");
 }
 
 value stub_inotify_struct_size(void){
-  CAMLparam0();
-  CAMLreturn(Val_int(-1));
+  caml_invalid_argument("stub_inotify_struct_size unimplemented");
 }
 
 value stub_inotify_convert(value buf){
-  CAMLparam1(buf);
-  CAMLlocal1(event);
-  event = caml_alloc_tuple(4);
-  Store_field(event, 0, Val_int(-1));
-  Store_field(event, 1, Val_emptylist);
-  Store_field(event, 2, caml_copy_int32(-1));
-  Store_field(event, 3, Val_int(-1));
-  CAMLreturn(event);
+  caml_invalid_argument("stub_inotify_convert unimplemented");
 }
 
+value stub_inotify_ioctl_fionread(value fd){
+  caml_invalid_argument("stub_inotify_ioctl_fionread unimplemented");
+}
+
+/* value stub_inotify_init(value unit){ */
+/*   return Val_unit; */
+/* } */
+
+/* value stub_inotify_add_watch(value fd, value path, value mask){ */
+/*   return Val_unit; */
+/* } */
+
+/* value stub_inotify_rm_watch(value fd, value wd){ */
+/*   return Val_unit; */
+/* } */
+
+/* value stub_inotify_struct_size(void){ */
+/*   return Val_unit; */
+/* } */
+
+/* value stub_inotify_convert(value buf){ */
+/*   return Val_unit; */
+/* } */
+
+/* value stub_inotify_ioctl_fionread(value fd){ */
+/*   return Val_unit; */
+/* } */
+
 #endif

ocaml/contrib/ocaml_inotify/test.inotify.ml

 (* unit testing inotify *)
 
+module Inotify = Ocaml_inotify.Inotify
 open Printf
 
 let _ =

ocaml/omake/emacs.mli

   val message : Writer.t -> ('a, unit, string, unit) format4 -> 'a
 end
 
-(* Send asyncronous messages to Emacs instances.
-   These functions will strip newlines, as
-   the filter-function is line-based. *)
+(* Send asyncronous messages to Emacs instances.  These functions strip newlines, since
+   the Emacs filter-function is line-based. *)
 module Async : sig
   val send : pid -> ('a, unit, string, unit) format4 -> 'a
   val send_all : ('a, unit, string, unit) format4 -> 'a
   val send_all_watching : Id.t -> ('a, unit, string, unit) format4 -> 'a
   val message : Id.t -> ('a, unit, string, unit) format4 -> 'a
 
-(* Tell all watching Emacsen to reload the elisp output file. *)
+  (* Tell all watching Emacsen to reload the elisp output file. *)
   val load_elisp_file : Id.t -> unit
 
-(* Tell all Emacsen to reload the server state. *)
+  (* Tell all Emacsen to reload the server state. *)
   val load_server_state_file : unit -> unit
 end
 

ocaml/omake/query.ml

       Log.printf "Sending signal 0 to pid %s returned %s.  Removing views."
         (Pid.to_string pid) (Core.Std.Exn.to_string exn);
       Ivar.fill ivar ();
+      Emacs.unregister pid >>= fun () ->
       Projects.kill (id, Some pid) >>= fun () ->
       Projects.update_all ())
 
       Deferred.unit
     | Register_emacs pid ->
       Emacs.register pid writer;
-      (* Don't return until the writer is closed.  This means the
-         connection was broken.
-         UPDATE: while this seems clever, it does not seem to be working.
-         I'm not sure why.  *)
-      watch_for_dead_emacs pid;
-      Writer.close_finished writer >>= fun () ->
-      Emacs.unregister pid
+      watch_for_dead_emacs pid
     | Send_to_emacs (pid, msg) ->
       begin
         match pid with

ocaml/omake/server.ml

   Ashell.rm Files.socket >>= fun () ->
   Log.wait () >>= fun () ->
   Log.printf "Starting controller on %s" Files.socket;
+  (* Tcp closes the reader and writer when the handler result is determined, so
+     there's no need to explicitly close the reader/writer from the handler. *)
   Tcp.Server.create ~on_handler_error:`Raise (Tcp.on_file Files.socket)
     (fun _ reader writer ->
       try_with (fun () ->
         Reader.read_sexp reader >>= function
         | `Eof ->
           Log.printf "Warning: Read Eof";
-          (* Tcp closes the reader and writer when the handler result is determined. *)
           Deferred.unit
         | `Ok s ->
           Log.printf "omake server received: %s" (Sexp.to_string s);
            Ignore the pipe failures. *)
           Writer.set_raise_when_consumer_leaves writer false;
           Query.handle writer (Query.t_of_sexp s)) >>= (function
-          | Ok () ->
-            (* Tcp closes reader and writer when the result is determined. *)
-            Deferred.unit
+          | Ok () -> Deferred.unit
           | Error exn ->
             Log.exn exn;
             Writer.writef writer "%s" (Elisp.error (Exn.to_string exn));
             Deferred.unit))
+  (* Ignore the resulting server value, since we never need to close it. *)
   >>= fun _ ->
   Log.printf "Accepting TCP connections.";
   watch_for_inotify_limit ();
     Tcp.with_connection (Tcp.to_file Files.socket) (fun reader writer ->
       Writer.write writer msg;
       Pipe.iter (Reader.pipe reader) ~f:(fun s ->
-      (* Write to the process's stdout *)
+        (* Write to the process's stdout *)
         printf "%s\n" s;
         Deferred.unit))