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

Fix C warning with OCaml 4.10 #751

Merged
merged 1 commit into from
Dec 14, 2019

Conversation

kit-ty-kate
Copy link
Member

OCaml 4.10 comes by default with -force-safe-string enabled which means String_val changes from char* to const char*. Bytes_val should be used instead.

The warning looked like this:

+ /home/opam/.opam/4.10.0+trunk/bin/dune "build" "-p" "lwt" "-j" "71" (CWD=/home/opam/.opam/4.10.0+trunk/.opam-switch/build/lwt.4.4.0)
-       ocamlc src/unix/unix_read_job.o
- unix_read_job.c: In function 'result_read':
- unix_read_job.c:52:40: warning: passing argument 1 of 'memcpy' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
-    52 |         memcpy(String_val(job->string) + job->offset, job->buffer, result);
- In file included from unix_read_job.c:15:
- /usr/include/string.h:42:14: note: expected 'void * restrict' but argument is of type 'const char *'
-    42 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
-       |              ^~~~~~
-       ocamlc src/unix/lwt_unix_stubs.o
- lwt_unix_stubs.c: In function 'lwt_unix_blit_to_bytes':
- lwt_unix_stubs.c:134:31: warning: passing argument 1 of 'memcpy' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
-   134 |   memcpy(String_val(val_buf2) + Long_val(val_ofs2),
- In file included from /usr/include/x86_64-linux-gnu/sys/un.h:37,
-                  from /home/opam/.opam/4.10.0+trunk/lib/ocaml/caml/socketaddr.h:22,
-                  from lwt_unix.h:15,
-                  from lwt_unix_stubs.c:35:
- /usr/include/string.h:42:14: note: expected 'void * restrict' but argument is of type 'const char *'
-    42 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
-       |              ^~~~~~

OCaml 4.10 comes by default with -force-safe-string enabled which means String_val changes from char* to const char*. Bytes_val should be used instead.
@aantron aantron merged commit ee191b5 into ocsigen:master Dec 14, 2019
@aantron
Copy link
Collaborator

aantron commented Dec 14, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants