Skip to content

Commit

Permalink
fix tests with -default-safe-string (OCaml 4.06)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrek committed Nov 26, 2017
1 parent da56222 commit ebe6f65
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
26 changes: 26 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ CURLLIBS
ac_prefix_program
OCAML_PKG_lwt_ppx
OCAML_PKG_lwt_unix
OCAML_PKG_bytes
OCAMLFIND
OCAMLBUILD
OCAMLDOC
Expand Down Expand Up @@ -4091,6 +4092,30 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OCaml findlib package bytes" >&5
$as_echo_n "checking for OCaml findlib package bytes... " >&6; }
unset found
unset pkg
found=no
for pkg in bytes ; do
if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }
OCAML_PKG_bytes=$pkg
found=yes
break
fi
done
if test "$found" = "no" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
OCAML_PKG_bytes=no
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OCaml findlib package lwt.unix" >&5
$as_echo_n "checking for OCaml findlib package lwt.unix... " >&6; }
Expand Down Expand Up @@ -4241,6 +4266,7 @@ fi
if test "$OCAMLFIND" == "no"; then :
$OCAMLC -I +compiler-libs ocamlcommon.cma print_ext.ml -o print_ext
else
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ AC_PROG_INSTALL()
AC_PROG_OCAML()
AC_PROG_FINDLIB()

AC_CHECK_OCAML_PKG([bytes])
AC_CHECK_OCAML_PKG([lwt.unix])
AC_CHECK_OCAML_PKG([lwt.ppx])

Expand All @@ -39,6 +40,7 @@ AC_SUBST(CURLLIBS)
AC_SUBST(OCAMLLIB)
AC_SUBST(INSTALLDIR)
AC_SUBST(OCAMLFIND)
AC_SUBST(OCAML_PKG_bytes)
AC_SUBST(OCAML_PKG_lwt_unix)
AC_SUBST(OCAML_PKG_lwt_ppx)

Expand Down
16 changes: 14 additions & 2 deletions examples/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ LFLAGS = -g -I .. -ccopt -L..
OCURLLIB = curl.cma unix.cma threads.cma
OCURLOPTLIB = curl.cmxa unix.cmxa threads.cmxa

TARGETS = ocurl oput ominimal ossl ocurl_test_threads opar test_cb_exn test_memory_leaks
TARGETS = ocurl ominimal ossl ocurl_test_threads opar test_cb_exn test_memory_leaks
ifneq (@OCAML_PKG_bytes@,no)
TARGETS += oput
endif
ifneq (@OCAML_PKG_lwt_unix@,no)
TARGETS += test_lwt_unit
ifneq (@OCAML_PKG_lwt_ppx@,no)
Expand All @@ -25,7 +28,10 @@ endif
endif

ifeq (@OCAMLBEST@,opt)
TARGETS += ocurl.opt oput.opt ominimal.opt ossl.opt ocurl_test_threads.opt opar.opt test_cb_exn.opt test_memory_leaks.opt
TARGETS += ocurl.opt ominimal.opt ossl.opt ocurl_test_threads.opt opar.opt test_cb_exn.opt test_memory_leaks.opt
ifneq (@OCAML_PKG_bytes@,no)
TARGETS += oput.opt
endif
ifneq (@OCAML_PKG_lwt_unix@,no)
TARGETS += test_lwt_unit.opt
ifneq (@OCAML_PKG_lwt_ppx@,no)
Expand All @@ -50,6 +56,12 @@ test_lwt_unit: ../curl.cma ../curl_lwt.cmo test_lwt_unit.ml
test_lwt_unit.opt: ../curl.cmxa ../curl_lwt.cmx test_lwt_unit.ml
$(FINDLIB) opt $(FINDLIB_LWT_FLAGS) $(LFLAGS) $^ -o $@

oput: ../curl.cma oput.ml
$(FINDLIB) c -custom -package bytes -linkpkg $(LFLAGS) $^ -o $@

oput.opt: ../curl.cmxa oput.ml
$(FINDLIB) opt -package bytes -linkpkg $(LFLAGS) $^ -o $@

%: %.cmo ../curl.cma
$(OCBYTE) -custom $(LFLAGS) $(OCURLLIB) $< -o $@

Expand Down
15 changes: 8 additions & 7 deletions examples/oput.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
let counter = ref 0

let reader file maxBytes =
let buffer = String.make maxBytes ' ' in
let buffer = Bytes.create maxBytes in
let readBytes = input file buffer 0 maxBytes in
if readBytes = 0 then ""
else
begin
counter := !counter + readBytes;
String.sub buffer 0 readBytes
end
if readBytes = 0 then
""
else
begin
counter := !counter + readBytes;
Bytes.sub_string buffer 0 readBytes
end

let _ =
if Array.length Sys.argv = 3 then
Expand Down

0 comments on commit ebe6f65

Please sign in to comment.