Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-ouput-obj problems #2959

Closed
vicuna opened this issue Sep 11, 2001 · 2 comments
Closed

-ouput-obj problems #2959

vicuna opened this issue Sep 11, 2001 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Sep 11, 2001

Original bug ID: 525
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Ohad Rodeh
Version: 3.02
OS: WIN2000
Submission from: gvul.haifa.il.ibm.com (192.115.216.67)

ocamlc -output-obj does not work well on WIN2000, especially with Unix
calls.

For example, the code below allows a C program (yy.c) to call
an ML function (in xx.ml). This call should print out the hostname
of the machine, the result is junk.

Any help would be appreciated. I'm also having various other problems
with code created by -output-obj on WIN2000, perhaps this will solve them
as well.

Thanks,
Ohad.

-------- File xx.ml -------------------------------------------------
open Printf

let c_hostname () =
let h = Unix.gethostname () in
printf "hostname=%s\n" h; flush stdout;
()

let _ =
Callback.register "c_hostname_v" c_hostname ;
()

--------- File yy.c -------------------------------------------------

#include "caml/mlvalues.h"
#include "caml/memory.h"
#include "caml/callback.h"
#include "caml/alloc.h"
#include "caml/config.h"

value *c_hostname_v = NULL;

int main (int argc, char *argv){
caml_startup(argv) ;
c_hostname_v = caml_named_value((char
) "c_hostname_v");

callback(*c_hostname_v, Val_unit);
}

--------- Makefile.nt -----------------------------------------------
CC = cl /nologo /Ox /MT /W3 /I$(CAMLLIB)

LIBSYSCL = -link /NODEFAULTLIB
ADVAPI32.lib
LIBCMT.lib
OLDNAMES.lib
KERNEL32.lib
WSOCK32.lib

##
.SUFFIXES: .ml .cmo .cmx .mli .cmi .c .o .obj .cmx
.mli.cmi:
ocamlc -c $< -o $@
.ml.cmo:
ocamlc -c $< -o $@
.ml.cmx:
ocamlopt -c $< -o $@
.c.o :
$(CC) -c $(CFLAGS) $< -o $@
.c.obj :
$(CC) -c $(CFLAGS) $< -o $@
#
#

all : zz.exe #xx.exe

xx.exe: xx.cmo
ocamlc -custom -o xx.exe unix.cma xx.cmo

zz.obj : xx.cmo
ocamlc -output-obj -o zz.obj unix.cma xx.cmo

zz.exe : zz.obj yy.obj xx.cmo
$(CC) -o zz.exe yy.obj zz.obj
$(CAMLLIB)\libunix.lib
$(CAMLLIB)\libcamlrun.lib
$(LIBSYSCL)

clean :
-del /Q*.obj *.exe .cm

@vicuna
Copy link
Author

vicuna commented Nov 27, 2001

Comment author: administrator

Fixed 2001-11-27 by XL.

@vicuna vicuna closed this as completed Nov 27, 2001
@vicuna
Copy link
Author

vicuna commented Nov 27, 2001

Comment author: administrator

Ohad,

My apologies for this late answer, I forgot about your message and
it's only now that I'm going over the open bug reports.

For example, the code below allows a C program (yy.c) to call
an ML function (in xx.ml). This call should print out the hostname
of the machine, the result is junk.

As it turns out, the problem is not specific to Windows, and affects
all uses of -output-obj. Briefly, the Caml initialization code terminates
by calling the functions registered by at_exit. Under Windows, Unix
registers one such function that shuts down the Winsock library.
Hence, when caml_startup returns, Winsock is no longer operational
and calls to Winsock functions (through Caml functions or directly)
fail.

This will be fixed in 3.03 by not calling at_exit functions if
-output-obj is specified. In the meantime, you can change
the following line in otherlibs/win32unix/unix.ml

    let _ = startup(); at_exit cleanup

to just

    let _ = startup()

Hope this helps,

  • Xavier Leroy

@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant