Discussion:
String.create
Sébastien Hinderer
2014-10-22 09:14:39 UTC
Permalink
Dear all,

OCaml 4.02.0 prints the following warning:
Warning 3: deprecated: String.create

The code that triggers this warning looks like this:

let buf = String.create size in
really_input ic buf 0 size;

Is there a way to fix the code so that it does not trigger this warning
but still compiles also with older versions of Caml, up to 3.10?

Many thanks!
Sébastien.
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
a***@comtv.ru
2014-10-22 09:26:05 UTC
Permalink
Post by Sébastien Hinderer
Dear all,
Warning 3: deprecated: String.create
let buf = String.create size in
really_input ic buf 0 size;
Is there a way to fix the code so that it does not trigger this warning
but still compiles also with older versions of Caml, up to 3.10?
String.make
--
mailto:***@comtv.ru
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
David Allsopp
2014-10-22 09:31:43 UTC
Permalink
Post by a***@comtv.ru
Post by Sébastien Hinderer
Dear all,
Warning 3: deprecated: String.create
let buf = String.create size in
really_input ic buf 0 size;
Is there a way to fix the code so that it does not trigger this
warning but still compiles also with older versions of Caml, up to 3.10?
String.make
Not a great solution (even ignoring the semantic differences between Bytes.create and String.make) - really_input has signature in_channel -> *bytes* -> int -> int -> unit for OCaml >= 4.02, so this will break in the future when -safe-string becomes the default.


David
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
David Allsopp
2014-10-22 09:27:26 UTC
Permalink
Post by Sébastien Hinderer
Warning 3: deprecated: String.create
let buf = String.create size in
really_input ic buf 0 size;
Is there a way to fix the code so that it does not trigger this warning
but still compiles also with older versions of Caml, up to 3.10?
Yes - write your code to use Bytes (http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bytes.html) and then add a requirement for findlib >= 1.5 which includes the "bytes" package (this is a dummy package for OCaml >= 4.02 and a compatibility layer for OCaml < 4.02).

Alternatively, if for some very strange reason you're not happy to depend on findlib, you can borrow its compatibility layer directly (src/bytes/bytes.ml) and integrate that into your build system.


David
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr
Sylvain Pogodalla
2014-10-22 09:29:36 UTC
Permalink
Hi,
Post by Sébastien Hinderer
Warning 3: deprecated: String.create
(...)
Post by Sébastien Hinderer
Is there a way to fix the code so that it does not trigger this warning
but still compiles also with older versions of Caml, up to 3.10?
You can pass the -w -3 option to the compiler to disable waring
messages on deprecated features.

Hop this helps.

S.
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Continue reading on narkive:
Loading...