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

various windows fixes #586

Merged
merged 2 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package_integers_path = $(shell $(OCAMLFIND) query integers)
ifneq (,$(filter mingw%,$(OSYSTEM)))
lib_process=-lpsapi
OCAMLMKLIB_EXTRA_FLAGS=-ldopt "-link -static-libgcc" # see GPR#1535
ifeq ($(DEBUG),false)
CFLAGS=-std=c99 -Wall -O3 $(OCAML_FFI_INCOPTS) "-I$(package_integers_path)"
else
Expand Down Expand Up @@ -93,10 +94,10 @@ $(BUILDDIR)/%.cmxa: $$(NATIVE_OBJECTS)
$(OCAMLFIND) opt -a -linkall $(OCAMLFLAGS) $(THREAD_FLAG) $(OCAMLFIND_PACKAGE_FLAGS) $(CMXA_OPTS) -o $@ $(NATIVE_OBJECTS) $(OCAML_LINK_FLAGS)

$(BUILDDIR)/dll%_stubs$(EXTDLL): $$(C_OBJECTS)
$(OCAMLMKLIB) -o $(BUILDDIR)/$*_stubs $^ $(OCAMLMKLIB_FLAGS)
$(OCAMLMKLIB) -o $(BUILDDIR)/$*_stubs $^ $(OCAMLMKLIB_FLAGS) $(OCAMLMKLIB_EXTRA_FLAGS)

$(BUILDDIR)/dll%_stubs_xen$(EXTDLL): $$(XEN_OBJECTS)
$(OCAMLMKLIB) -o $(BUILDDIR)/$*_stubs_xen $^ $(OCAMLMKLIB_FLAGS)
$(OCAMLMKLIB) -o $(BUILDDIR)/$*_stubs_xen $^ $(OCAMLMKLIB_FLAGS) $(OCAMLMKLIB_EXTRA_FLAGS)

$(BUILDDIR)/%.cmxs : $$(NATIVE_OBJECTS)
$(OCAMLFIND) opt -shared -linkall $(OCAMLFLAGS) $(THREAD_FLAG) $(OCAMLFIND_PACKAGE_FLAGS) -o $@ $(NATIVE_OBJECTS) $(C_OBJECTS) $(OCAML_LINK_FLAGS)
Expand Down
4 changes: 4 additions & 0 deletions src/configure/extract_from_c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ let extract s =
String.sub s begin_pos (end_pos - begin_pos)

let headers = "\
#if defined(__MINGW32__) || defined(__MINGW64__)
#define __USE_MINGW_ANSI_STDIO 1
#include <stdio.h> /* see: https://sourceforge.net/p/mingw-w64/bugs/627/ */
#endif
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
Expand Down
8 changes: 2 additions & 6 deletions src/cstubs/cstubs_structs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ let cstring s =
in "\""^ escaped ^"\""

let cprologue = [
"#if !__USE_MINGW_ANSI_STDIO && (defined(__MINGW32__) || defined(__MINGW64__))";
"#define __USE_MINGW_ANSI_STDIO 1";
"#endif";
"";
"#include <stdio.h>";
"#include <stddef.h>";
"#include \"ctypes_cstubs_internals.h\"";
Expand All @@ -54,11 +50,11 @@ let puts fmt s = Format.fprintf fmt "@[puts@[(%s);@]@]@\n"
(cstring s)

(* [printf1 fmt s v] writes the call [printf(s, v);] on [fmt]. *)
let printf1 fmt s v = Format.fprintf fmt "@[printf@[(%s,@ %t);@]@]@\n"
let printf1 fmt s v = Format.fprintf fmt "@[ctypes_printf@[(%s,@ %t);@]@]@\n"
(cstring s) v

(* [printf2 fmt s u v] writes the call [printf(s, u, v);] on [fmt]. *)
let printf2 fmt s u v = Format.fprintf fmt "@[printf@[(%s,@ %t,@ %t);@]@]@\n"
let printf2 fmt s u v = Format.fprintf fmt "@[ctypes_printf@[(%s,@ %t,@ %t);@]@]@\n"
(cstring s) u v

(* [offsetof fmt t f] writes the call [offsetof(t, f)] on [fmt]. *)
Expand Down
6 changes: 6 additions & 0 deletions src/ctypes/ctypes_cstubs_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ static inline value ctypes_pair_with_errno(value p)
CAMLreturn (v);
}

#if defined(__MINGW32__) || defined(__MINGW64__)
#define ctypes_printf __mingw_printf
#else
#define ctypes_printf printf
#endif

#endif /* CTYPES_CSTUBS_INTERNALS_H */
13 changes: 13 additions & 0 deletions tests/test-foreign-errno/test_errno.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ let suite = "foreign+errno tests" >:::


let _ =
if Sys.os_type = "Win32" then
(*
Ugly workaround because oUnit raises an error, if there are
any changes in the environment.

There are two ways to access the environments on windows:
- through the native Windows API.
- through the crt lib. The crt uses the environment for interprocess
communication, but hides it from the end user.
Since OCaml 4.07 the native Windows API is used by Unix.environment,
therefore the tricks of the crt lib are visible.
*)
Sys.chdir "."; (* udpate environment *)
run_test_tt_main suite
13 changes: 10 additions & 3 deletions tests/test-value_printing/test_value_printing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,18 @@ struct
let _FLT_MIN = retrieve_FLT_MIN () in
let _FLT_MAX = retrieve_FLT_MAX () in

assert_equal (string_of float _FLT_MIN) (string_of_float _FLT_MIN);
let rex = Str.regexp "e\\([-+]\\)[0]+\\([1-9]+\\)" in
let exp_equal a b =
(* remove leading zeros from exponential form *)
let a = Str.global_replace rex "e\\1\\2" a in
let b = Str.global_replace rex "e\\1\\2" b in
assert_equal a b in

exp_equal (string_of float _FLT_MIN) (string_of_float _FLT_MIN);
assert_equal (valid_float_lexem (string_of float 0.0)) (string_of_float 0.0);
assert_equal (string_of float nan) (string_of_float nan);
assert_equal (string_of float infinity) (string_of_float infinity);
assert_equal (string_of float _FLT_MAX) (string_of_float _FLT_MAX);
exp_equal (string_of float _FLT_MAX) (string_of_float _FLT_MAX);

(* double *)
let _DBL_MIN = retrieve_DBL_MIN () in
Expand All @@ -224,7 +231,7 @@ struct
assert_equal (valid_float_lexem (string_of double 0.0)) (string_of_float 0.0);
assert_equal (string_of double (-1.03)) (string_of_float (-1.03));
assert_equal (string_of double (34.22)) (string_of_float (34.22));
assert_equal (string_of double (1.39e16)) (string_of_float (1.39e16));
exp_equal (string_of double (1.39e16)) (string_of_float (1.39e16));
assert_equal (string_of double nan) (string_of_float nan);
assert_equal (string_of double infinity) (string_of_float infinity);
assert_equal (string_of double _DBL_MAX) (string_of_float _DBL_MAX);
Expand Down